Can someone explain me the difference between writing layout management in this format i.e, in two lines
e1 = Entry(root, textvariable=x)
e1.grid(row=1, column=2)
and writing layout management in this format i.e., in one line
e1 = Entry(root, textvariable=x).grid(row=1, column=2)
Why can't I use get()
when I write layout management in single line.
In python, when you do
x=y().z()
,x
is set to the result of.z()
.pack
,grid
, andplace
all are designed to returnNone
. Thus,e1 = Entry(root, textvariable=x).grid(row=1, column=2)
returnNone
Soe1
isNone
. The valueNone
doesn’t have any methods which is why you get the errorAttributeError: 'NoneType' object has no attribute 'get'
Further, in my experience, it is always better to separate widget creation from widget layout. Trying to put it all on one line makes the code harder to understand and harder to maintain. By separating the code and grouping layout commands together it makes it much easier to visualize the layout just by looking at the code.