Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Tkinter获取条目_Python_Python 3.x_Python 2.7_Tkinter - Fatal编程技术网

Python 使用Tkinter获取条目

Python 使用Tkinter获取条目,python,python-3.x,python-2.7,tkinter,Python,Python 3.x,Python 2.7,Tkinter,你好,我有这个代码: 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

你好,我有这个代码:

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'
我必须使用网格绝对,但我不知道为什么我得到这个错误

你能帮我吗

谢谢:

现在的条目是网格的返回,它总是无。将显示调用与小部件对象启动分开。替换:

entry = tk.entry(root).grid(row=1,column=1)
与:


上面的代码不会引发您声称的错误。它引发AttributeError:“模块”对象没有属性“条目”。它可以通过大写输入的初始字符来固定:entry。。。。
entry = tk.Entry(root) # no predefined class named entry
entry.grid(row=1,column=1)