开发者

wxPython equivalent to Tkinter's protocol attribute?

开发者 https://www.devze.com 2023-02-12 17:55 出处:网络
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).

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消