Python - Tkinter 'attributeerror: 'nonetype' Object Has No Attribute 'xview''
I'm trying to place a scrollbar on a DISABLED Entry widget. However it keeps coming up with the error AttributeError: 'NoneType' object has no attribute 'xview'. Is it because no v
Solution 1:
The problem is that grid
returns None
, not self
.
So, when you do this:
decimalView = ttk.Entry(mainframe, state = DISABLED, background = "gray99", width =30, textvariable =decimal).grid(column=2, row=2, sticky = W)
… you're setting decimalView
to None
. Which is why the error message tells you that it can't find an xview
attribute on None
.
And this isn't some weird quirk of Tkinter; almost every method in Python that mutates an object in any way returns None
(or, sometimes, some other useful value—but never self
), from list.sort
to file.write
.
Just write it on two lines: construct the Entry
and assign it to decimalView
, and then grid
it.
Besides the minor benefit of having working code, you'll also have more readable code, that doesn't scroll off the right side of the screen on StackOverflow or most text editors.
Post a Comment for "Python - Tkinter 'attributeerror: 'nonetype' Object Has No Attribute 'xview''"