Tk from IDLE: How to 'Hello World'?

Kirby Urner urner at alumni.princeton.edu
Fri Sep 29 02:18:01 CEST 2000


Tk in Windows IDLE does not work the way tutorials suggest.
For example, consider Fredrik Lundh's 'Hello World' app at
http://www.pythonware.com/library/tkinter/introduction/hello-tkinter.htm


Writing it interactively in IDLE, one would go:

 >>> from Tkinter import *
 >>> def test():
	root = Tk()
        w = Label(root, text="Hello, world!")
        w.pack()
        root.mainloop()

 >>> test()

Which gets you the Tk window saying Hello World, as expected.  

But then if you hit the close box, do you get back to a working 
IDLE prompt?  I don't.  I'm left in limbo, with a prompt I can't
go back to.

I haven't tested this in LINUX IDLE yet, nor in 1.5.2 -- so 
maybe this is a new phenomenon with the latest beta?  Or is
it some problem with my setup?  Could another Windows user 
provide a reality check here?

Anyway, Lundh's book and many other resources do not appear 
to be written with IDLE in mind.  For example it states:

      To run the program, run the script as usual:

      $ python hello1.py

But that's not 'usual' for an IDLE user.  There's no $ prompt,
and we're already in Python, and so wouldn't invoke it.

As someone interested in using Python in schools, I think
a GUI like IDLE is a potentially better learning environment 
than a command line in DOS or Xterm.  I would like to see more
bias in favor of using IDLE when doing work with Tk (IDLE 
being itself a Tk app, after all, and cross-platform).

Kirby




More information about the Python-list mailing list