Tkinter - the app that wouldn't quit

Randall Hopper aa8vb at vislab.epa.gov
Fri Apr 16 14:48:31 EDT 1999


     I'm writing a test wrapper for a dialog module that doesn't terminate
the application.  How can I exit the test program when the dialog is
dismissed?

     Attached is a minimal version that illustrates the problem.  When it
self.destroy()'s itself, we're hung.  mainloop() is still spinning.
As you can see, I did try WM_DELETE_WINDOW.

Thanks for any tips,

Randall

-------------- next part --------------
#!/usr/bin/env python

import sys
from Tkinter import *
from ScrolledText import ScrolledText

class CommandWindow(ScrolledText):

    def __init__(self, master=None, **cnf):
        apply(ScrolledText.__init__, (self, master), cnf)

class CommandWindowDialog(Toplevel):

    def __init__(self, master=None, **cnf):
        apply(Toplevel.__init__, (self, master), cnf )
        self.title( 'COMMAND OUTPUT' )
        win = CommandWindow( self )
        win.pack(expand=1, fill=X)
	btn = Button( self, text="Quit", command=self.destroy )
	btn.pack()

root = Tk()
w = CommandWindowDialog( root )
w.protocol( 'WM_DELETE_WINDOW', sys.exit )
root.wm_withdraw()
w.mainloop()


More information about the Python-list mailing list