blob: 805a6bc6a8c524caa5ad16c3018b5775d3279d3b [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
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).
6
7
8### ******* this isn't really called -- read the comments
9def my_delete_callback():
10 print "whoops -- tried to delete me!"
11
12class Test(Frame):
13 def deathHandler(self, event):
14 print self, "is now getting nuked. performing some save here...."
15
16 def createWidgets(self):
17 # a hello button
Guido van Rossum89cb67b1996-07-30 18:57:18 +000018 self.hi_there = Button(self, text='Hello')
19 self.hi_there.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000020
21 def __init__(self, master=None):
22 Frame.__init__(self, master)
23 Pack.config(self)
24 self.createWidgets()
25
26 ###
27 ### PREVENT WM kills from happening
28 ###
29
30 # the docs would have you do this:
31
32# self.master.protocol("WM_DELETE_WINDOW", my_delete_callback)
33
34 # unfortunately, some window managers will not send this request to a window.
35 # the "protocol" function seems incapable of trapping these "aggressive" window kills.
36 # this line of code catches everything, tho. The window is deleted, but you have a chance
37 # of cleaning up first.
38 self.bind_all("<Destroy>", self.deathHandler)
39
40
41test = Test()
42test.mainloop()