[Tutor] A simple problem with Tkinter

Rick Pasotto rick at niof.net
Thu Sep 30 16:36:58 CEST 2004


On Thu, Sep 30, 2004 at 07:27:30AM -0700, Ali Polatel wrote:
> you should pack them!
> from Tkinter import *
> root=Tk()
> w=Label(root,text="Hello!!")   Correct is  w=Label(root,text="Hello!!").pack()

Not really. Better would be:

w=Label(root,text="Hello!!")
w.pack()

This retains a reference to the label for later modification if desired.
What you have done is to assign the useless return value of pack() to w.

> b=Button(root,text="Bye",command='exit') 
> Correct is b=Button(root,text="Bye",command='exit').pack()

Same as above.

> root.mainloop()

The main point is that creating a label or button does not display it.
You need to use pack() or grid() to place and display it.

-- 
"Certainly virtue is like precious odours, most fragrant when they are
 incensed, or crushed: for prosperity doth best discover vice, but
 adversity doth best discover virtue."
	-- Francis Bacon, essayist, philosopher, and statesman (1561-1626)
    Rick Pasotto    rick at niof.net    http://www.niof.net


More information about the Tutor mailing list