【问题标题】:wxPython equivalent to Tkinter's protocol attribute?wxPython 相当于 Tkinter 的协议属性?
【发布时间】:2011-06-30 16:19:43
【问题描述】:
Tkinter 中的协议属性允许在单击窗口的退出按钮时运行函数(带有 x 的按钮,它在 Windows 中的右上角)。
我想在用户尝试退出我的应用程序时运行一个函数。有 wxPython 等价物吗?
sn-p:
self.protocol("WM_DELETE_WINDOW", self.do_something)
【问题讨论】:
标签:
python
windows
wxpython
protocols
tkinter
【解决方案1】:
当您单击关闭按钮时,您将产生一个EVT_CLOSE 事件,因此如果您将此事件绑定到onClose 方法,那么您可以在实际关闭应用程序之前执行任何您想要的操作。一个简单的例子:
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()