wasm-demo/demo/ermis-f/python_m/cur/1460

65 lines
2.1 KiB
Plaintext

From: aa8vb at vislab.epa.gov (Randall Hopper)
Date: Mon, 19 Apr 1999 13:50:13 GMT
Subject: Tkinter - the app that wouldn't quit
In-Reply-To: <m3pv51xg9g.fsf@devel.no.rwd.dinet>; from Rob Hooft on Mon, Apr 19, 1999 at 08:42:51AM +0200
References: <19990416144831.A1548022@vislab.epa.gov> <m3pv51xg9g.fsf@devel.no.rwd.dinet>
Message-ID: <19990419095013.A62714@vislab.epa.gov>
Content-Length: 1685
X-UID: 1460
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()