Tkinter and IDE's
support at internetdiscovery.com
Fri Nov 23 22:48:50 CET 2001
On Wed, 21 Nov 2001 02:46:15 GMT, "Don Arnold" <darnold02 at sprynet.com>
>Here's the simple code I was trying to run (from 'Programming Python', 2nd
Thanks for the explicit example. The problem is in your code, not
>from Tkinter import *
This is unfortunately the cause of the problem in this case.
In Python, if you're having troubles, remove all the 'import *'
you can find and replace them with 'import' for safety.
> print "Hello, I must be going"
The problem here is that root is not your root - it's a default
root in Tkinter that came in with your 'import *'. The is an evil
timesaving feature of Tkinter that I would like to see removed.
It is the first instance of a Tk(), which in this case happens to
be Idle's. So your quit() says 'quit Idle'.
>root = Tk()
This root is your root, which is a different root from quit().
>widget = Button(root, text="Hello, event world", command = quit)
This is correct, but it should be followed by a root.destroy().
root.quit() quits the mainloop, but *does not destroy myroot*.
My revised version of your program is:
myroot = Tkinter.Tk()
print "Hello, I must be going"
# import sys
widget = Tkinter.Button(myroot, text="Hello, event world",
command = quit)
>When I run it in IDLE, the tk window pops fine. Clicking the button once
>outputs the message to the interactive window as expected, but doesn't
>shutdown the tk window. Clicking the button a second time shuts down the tk
>window, and IDLE along with it. I just found that if I delete(root) in the
>interactive window before the 2nd click, the tk window closes and I raise a
>NameError exception on 'root', but at least IDLE stays up and running.
My revised version of your program does what you expect, and doesn't
kill Idle, because root.quit() isn't called. Maybe you should send a
note to the author of Programming Python to say that using Tkinter's
default root is confusing, and perhaps the example could be rewritten.
>Sorry for being vague earlier.
Thank's for the explicit example. Actually there is still a problem
left here (the Tcl interpreter is not completely and cleanly destroyed
by myroot.destroy()), but that's another issue.
>Hope this helps,
It did - it helped me find a bug in my Tkinter debugging tools!
(http://tix.sourceforge.net/Tide in Tkinspect.py)
More information about the Python-list