我已经看到类似的错误消息,但找不到解决方案,将解决它在我的情况下的几个其他职位。Tkinter:AttributeError:NoneType对象没有属性获取
我用TkInter玩了一下,创建了一个非常简单的用户界面。代码如下 -
from string import *
from Tkinter import *
import tkMessageBox
root=Tk()
vid = IntVar()
def grabText(event):
if entryBox.get().strip()=="":
tkMessageBox.showerror("Error", "Please enter text")
else:
print entryBox.get().strip()
root.title("My Sample")
root.maxsize(width=550, height=200)
root.minsize(width=550, height=200)
root.resizable(width=NO, height=NO)
label=Label(root, text = "Enter text:").grid(row=2,column=0,sticky=W)
entryBox=Entry(root,width=60).grid(row=2, column=1,sticky=W)
grabBtn=Button(root, text="Grab")
grabBtn.grid(row=8, column=1)
grabBtn.bind('<Button-1>', grabText)
root.mainloop()
我启动并运行了UI。当我点击Grab
按钮,我得到的控制台上看到以下错误:
C:\Python25>python.exe myFiles\testBed.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
File "myFiles\testBed.py", line 10, in grabText
if entryBox.get().strip()=="":
AttributeError: 'NoneType' object has no attribute 'get'
错误追溯到Tkinter.py
。
我确信有人可能以前曾处理过这个问题。任何帮助表示赞赏。
更多详情[** here **](https://www.begueradj.com/tkinter-saya-idiom.html) – 2017-06-27 07:50:47