【发布时间】:2018-03-21 11:17:44
【问题描述】:
你好,我有这个代码:
import Tkinter as tk
root = tk.Tk()
margin = 0.23
entry = tk.entry(root).grid(row=1,column=1)
def profit_calculator():
profit = margin*int(entry.get())
print(profit)
button_calc = tk.Button(root, text="Calculate", command=profit_calculator).grid(row=2,column=1)
root.mainloop()
我试图执行这段代码,我在条目中输入了一个值,但是当我点击按钮时,我得到了这个:
AttributeError : 'NoneType' object has no attribute 'get'
我必须绝对使用网格,但我不知道为什么会出现这个错误...
你能帮帮我吗?
谢谢你:)
【问题讨论】:
-
上面的代码不会引发您声称的错误。它引发了
AttributeError: 'module' object has no attribute 'entry'。可以通过将条目的初始字符大写来修复:Entry(...。
标签: python python-3.x python-2.7 tkinter