我在类似的错误消息上看到了其他一些帖子,但找不到可以解决我的问题的解决方案.
我用TkInter稍微涉足并创建了一个非常简单的UI.该守则如下─
from tkinter import *
root = Tk()
def grabText(event):
print(entryBox.get())
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()
Run Code Online (Sandbox Code Playgroud)
我启动并运行UI.当我单击Grab
按钮时,我在控制台上收到以下错误:
C:\Python> python.exe myFiles\testBed.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python\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'
Run Code Online (Sandbox Code Playgroud)
错误追溯到entryBox
.
我敢肯定有人可能以前处理过这个问题.任何帮助表示赞赏.
我正在使用 Python 的 tkinter 模块,我想仅在按下按钮时更改按钮的颜色。所以举个例子,通常按钮是白色的,但是当我按下它时,它会变成绿色。如果我停止按下它,它会变回白色。那可能吗?