Tkinter - the app that wouldn't quit

Randall Hopper aa8vb at vislab.epa.gov
Mon Apr 19 09:50:13 EDT 1999


Rob Hooft:
 |The problem in your current program appears to be that when your
 |application window is destroyed, "root" is still an active window,
 |although it is invisible.
 |
 |The WM_DELETE protocol is never called, because you're not
 |"destroying" the window using the window manager.

Ok.  That makes sense.

 |The smallest change would be to make the "Quit" button run "sys.exit"
 |immediately instead of "self.destroy".

The problem here is that this is supposed to be a reusable dialog which
doesn't exit the app.  In reality, the button says "Dismiss" not "Quit".
Hitting it just destroys the dialog (and all the processing guts inside,
which I've deleted) and the app continues.

Only for the test wrapper do I want to exit the app -- since it's the only
window displayed.

Do I need to add special testing-harness hooks into the dialog class, or is
there a general way to determine when a dialog destroys/unmaps itself from
outside of the dialog code?

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