[Tutor] Tkinter

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Apr 29 17:14:28 EDT 2004


> Can anybody tell, what is the difference between
> 
>     label = Label(root, text="Label1").grid()

This creates a widget and calls the grid method. It stores 
the result of the grid method('None' as it happens) in 
the variable label.

>     label = Label(root, text="Label1")

This creates a Label widget and stores it in the variable label

>     label.grid()

And this places the widget called 'label' in the UI using 
the grid() method.

> Which method is better to use?

Assuming you want to refer to 'label' in the future the second 
is the only one that makes sense. The first one will always 
result in 'label' being None, which is not very useful.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list