I have a tk.Entry widget, that I need to have focus_set()
on, and also need the function grid()
. Here's the piece of code:
e = Entry(...).focus_set()
e.grid(columnspan=3)
But the interpreter gives this problem:
Traceback (most recent call last):
File "D:\...\main.py", line 10, in <module>
e.grid(columnspan=3)
AttributeError: 'NoneType' object has no attribute 'grid'
Also, if I try to put all the functions in one line it gives same error for the function that goes after first (error for grid()
if Entry(...).focus_set().grid(...)
and same in reverse). What do I do?
CodePudding user response:
focus_set()
does not return the Entry
itself, but None
, so you simply said can't chain the calls like that.
Instead, just call them separately.
e = Entry(...)
e.focus_set()
e.grid(columnspan=3)