Exiting Tkinter when using IDLE
Jason Harper
JasonHarper at pobox.com
Fri Mar 12 14:21:22 EST 2004
An update to this advice I gave:
> 1. Don't use the quit method, instead just close your window. Your QUIT
> button could perhaps use:
> command=self.destroy
>
> 2. Don't call mainloop() if IDLE already has one running. Try this:
>
> import sys
> if "idlelib" not in sys.modules:
> root.mainloop()
This only works (on Windows, at least) if IDLE is _not_ running user
code in a subprocess. I've not found any combination of options that
gets usable results (including the ability to introspect the program
while running) when using a subprocess.
Also, it seems to leave the process running forever if launched outside
of IDLE, even after all the windows are closed. The simplest solution,
assuming a single-window application, seems to be giving the main window
a WM_DELETE_WINDOW protocol handler that does a self.quit(), but only if
IDLE isn't running (determined as shown above).
Here's a little inconsistency that had me really confused for a while:
IDLE, when run from the Start menu (Win2K Pro, Python 2.3.3), uses a subprocess.
IDLE, when run via "Open in IDLE" in a .py* file's right-click menu,
does NOT use a subprocess.
I haven't tracked down just where this difference is coming from.
Jason Harper
More information about the Python-list
mailing list