[d]wxPython的button点击响应事件为什么发生两次
使用的版本信息为:
python:2.5.1
wxPython:wxPython2.8-win32-unicode-2.8.7.1-py25
代码如下:
import wxclass MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="Hello My World") b = wx.Button(self, -1, "Create and Show a Frame", (50,50)) self.Bind(wx.EVT_BUTTON, self.OnButton, b) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Show() def OnButton(self, evt): dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!', 'A Message Box', wx.OK | wx.ICON_INFORMATION #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() evt.Skip() def OnClose(self, evt): dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?', 'Closing...', wx.YES_NO | wx.ICON_QUESTION) ret = dlg.ShowModal() dlg.Destroy() if ret == wx.ID_YES: evt.Skip()app = wx.App(0)MyFrame()app.MainLoop()