每次单击wx.Frame或按键盘上的键时,EVT_CLOSE都会被触发

时间:2014-11-18 18:55:51

标签: python wxpython wxwidgets

每次运行python脚本时,我都在运行以下类:

class MySplashScreen(wx.SplashScreen):
    def OnSplashScreenExit(self,e):
        self.Hide();
        frame = MyFrame(None)

    def __init__(self,parent=None):
        if "linux" in sys.platform or "darwin" in sys.platform:       
             bmp = wx.Bitmap(PATH + '/../icons/DNA.png', wx.BITMAP_TYPE_PNG)
        elif "win" in sys.platform and not 'darwin' in sys.platform:      
             bmp = wx.Bitmap(PATH + '\..\icons\DNA.png', wx.BITMAP_TYPE_PNG)       

        wx.SplashScreen.__init__(self,bmp,wx.SPLASH_CENTER_ON_SCREEN | wx.SPLASH_TIMEOUT,SPLASH_TIMEOUT,parent)
        self.Bind(wx.EVT_CLOSE,self.OnSplashScreenExit)

但是当我点击MyFrame上的任何地方时,另一个MyFrame会打开。调试时我发现每次单击MyFrame上的任意位置或按键盘上的任意键时,都会运行OnSplashScreenExit函数。有人可以帮我解决这个问题。这个问题在linux中无法生成。它只出现在我的带有python2.7系统的Windows 8.1上。

1 个答案:

答案 0 :(得分:0)

我可以通过进行以下更改来修复它:

if "win" in sys.platform:
         self.OnSplashScreenExit("")
else:
         self.Bind(wx.EVT_CLOSE,self.OnSplashScreenExit)