Is .grid on the same line different as to on a seperate line [duplicate]
In tkinter if you add a widget in the window in this way:
btn = Button().grid()
you lose the control on the widget because the .grid()
method returns None
.
The correct way is:
btn = Button()btn.grid()
you can understand why if you create a custom class:
class Person: def __init__(self, name: str): self.name = name def get_name(self): return self.nameif __name__ == "__main__": p = Person(name="Alex") print(type(p)) p = Person(name="Alex").get_name() print(type(p))
output
<class '__main__.Person'><class 'str'>