Exiting Tkinter when using IDLE

Kurt B. Kaiser kbk at shore.net
Sat Mar 13 08:00:44 CET 2004


"Batista, Facundo" <FBatista at uniFON.com.ar> writes:

> #- 1. Don't use the quit method, instead just close your 
> #- window.  Your QUIT
> #- button could perhaps use:
> #- 	command=self.destroy
>
> Used command=master.destroy. This way I'm telling "destroy" to the Tk
> instance.

When the last widget is destroyed, the mainloop exits.

[...]

> As Gerrit Muller, I think this should be standard information. It's
> important because Tkinter is the built in GUI and IDLE is the built
> in IDE.

Start the Python interpreter (not IDLE) and run your code using
self.quit.  You'll see it that it works.  Now run two Pythons at the
same time with that code.  Everything is fine, self.quit works for
both.  So it's not some interaction with the windowing system.

When IDLE uses its subprocess, the intent is that there are two
separate processes, each with a Tkinter application running.  One is
the user's, the other is the IDLE GUI's.  This should work as well as
the example in the previous paragraph.

When IDLE doesn't use a subprocess, the user's Tk gets mixed with
IDLE's, and it's not surprising things fail.

For me, on OpenBSD, Linux, and W2K, using the subprocess: if I use
self.quit, the Dialog becomes unresponsive because the mainloop has
been exited.  But the advertised action on mainloop exit is to destroy
any remaining widgets, and that's not happening.  If I restart the
shell, the Tk widget is destroyed correctly.

This certainly appears to be a bug in IDLE.  It's been reported 
before:

https://sourceforge.net/tracker/index.php?func=detail&aid=661324&group_id=9579&atid=109579

First person to get me a solution gets their name in the IDLE credits.

Hint: some part of the IDLE GUI namespace is being passed to the subprocess.

      import sys
      sys.modules.keys()

-- 
KBK



More information about the Python-list mailing list