changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Demo / tkinter / matt / killing-window-w-wm.py
blob6ec3464f2fbb99ffb989a3db5360a41dcf189700
1 from Tkinter import *
3 # This file shows how to trap the killing of a window
4 # when the user uses window manager menus (typ. upper left hand corner
5 # menu in the decoration border).
8 ### ******* this isn't really called -- read the comments
9 def my_delete_callback():
10 print "whoops -- tried to delete me!"
12 class Test(Frame):
13 def deathHandler(self, event):
14 print self, "is now getting nuked. performing some save here...."
16 def createWidgets(self):
17 # a hello button
18 self.hi_there = Button(self, {'text': 'Hello'})
19 self.hi_there.pack({'side': 'left'})
22 def __init__(self, master=None):
23 Frame.__init__(self, master)
24 Pack.config(self)
25 self.createWidgets()
27 ###
28 ### PREVENT WM kills from happening
29 ###
31 # the docs would have you do this:
33 # self.master.protocol("WM_DELETE_WINDOW", my_delete_callback)
35 # unfortunately, some window managers will not send this request to a window.
36 # the "protocol" function seems incapable of trapping these "aggressive" window kills.
37 # this line of code catches everything, tho. The window is deleted, but you have a chance
38 # of cleaning up first.
39 self.bind_all("<Destroy>", self.deathHandler)
42 test = Test()
43 test.mainloop()