wxPython equivalent to Tkinter's protocol attribute?
The protocol attribute in Tkinter allows one to run functions when the exit button of a window has been clicked (the button with the x on it, it's top right in Windows).
I'd like to run a function when the user try's to exit my application. Is there a wxPython equivalent?
snippe开发者_如何学Pythont:
self.protocol("WM_DELETE_WINDOW", self.do_something)
When you click on the close button you are producing an EVT_CLOSE
event so if you bind this event to an onClose
method then you can execute whatever you want before actually closing the application. A simple example:
class ChildFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.Bind(wx.EVT_CLOSE, self.on_close)
def on_close(self, evt):
process_whatever_you_want()
self.Destroy()
精彩评论