Exiting Tkinter when using IDLE
JasonHarper at pobox.com
Fri Mar 12 20:21:22 CET 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:
> 2. Don't call mainloop() if IDLE already has one running. Try this:
> import sys
> if "idlelib" not in sys.modules:
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.
More information about the Python-list