Tkinter: AttributeError: NoneType object has no attribute <attribute name>
The grid
, pack
and place
functions of the Entry
object and of all other widgets returns None
. In python when you do a().b()
, the result of the expression is whatever b()
returns, therefore Entry(...).grid(...)
will return None
.
You should split that on to two lines like this:
entryBox = Entry(root, width=60)entryBox.grid(row=2, column=1, sticky=W)
That way you get your Entry
reference stored in entryBox
and it's laid out like you expect. This has a bonus side effect of making your layout easier to understand and maintain if you collect all of your grid
and/or pack
statements in blocks.
Change this line:
entryBox=Entry(root,width=60).grid(row=2, column=1,sticky=W)
into these two lines:
entryBox=Entry(root,width=60)entryBox.grid(row=2, column=1,sticky=W)
Just as you already correctly do for grabBtn
!
For entryBox.get()
to access get()
method you need Entry object but Entry(root, width=60).grid(row=2, column=1, sticky=W)
returns None.
entryBox = Entry(root, width=60)
creates a new Entry Object.
Moreover, you won't needentryBox = entryBox.grid(row=2, column=1, sticky=W)
as it will rewrite entryBox
with None
Just replace entryBox = entryBox.grid(row=2, column=1, sticky=W)
with
entryBox = Entry(root, width=60)entryBox.grid(row=2, column=1, sticky=W)