当前位置: 动力学知识库 > 问答 > 编程问答 >

wxpython - Python WxWidgets : how to add hook called when window close button is pressed

问题描述:

I have a Python WxWidgets program, and have a "File->Quit" menu option that calls a quit function that cleanly shuts down my application. However, the application can also be closed by pressing the 'X' in the top right of the window. I would like to add a hook to capture that window close event to do my clean shutdown. How do I do that?

My main window is created with these options:

wx.Frame.__init__(self, parent, title=title, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)

网友答案:

ummm

def __init__(self,parent,title,...):
      wx.Frame.__init__(self, parent, title=title, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
      self.Bind(wx.EVT_CLOSE,self.OnClose)

def OnClose(self,evt):
      print "CLOSE!!!"
      self.Destroy()
分享给朋友:
您可能感兴趣的文章:
随机阅读: