[Tutor] Tinkering with Tkinter

Alan Gauld alan.gauld at btinternet.com
Tue May 26 09:51:36 CEST 2009

"Doug Reid" <rnrcreid at yahoo.com> wrote

> The following code and it's explanation doesn't seem to work:
1. >>> from Tkinter import *
2. >>> tk = Tk()
3. >>> btn = Button(tk, text="click me")
4. >>> btn.pack()
> In line 1, .....
> Nothing appears on the screen after I enter line 2...

A lot depends on the environment for Tk. It works slightly 
differently on different operating systems and with different 
IDEs. It is even possible that you wouldn't see any windows 
after line 4. You would need to add line 5:

>>> tk.mainloop() 

before anything happens.

Don't worry too much, just enter the code and run it.
If you do want to use the >>> prompt to experiment 
use an OS command line window rather than an IDE.

In pratice when working with Tkinter I've leaned not to trust 
any IDE but just use it as a text editor. I type the code, save 
it and then run it from the OS directly.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list