I've created this simple GUI:
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()
When I click on the Grab
button, an error occurs:
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'
Why is entryBox
set to None
?
See also Why do I get AttributeError: 'NoneType' object has no attribute 'something'? for the general case.
None
, and the design decision behind that (command-query separation). There are many of them, but it is the same problem every time. That covers the other aspect of this problem - stackoverflow.com/questions/8949252 covers understanding the error message. – Reward