当wxPython帧关闭时,Python崩溃 - 仅在XP上崩溃

时间:2012-09-19 02:20:44

标签: python wxpython

所以我的脚本中有一套相当复杂的wxPython框架。如果有必要,我会发布所有代码,但我不知道必然存在代码问题,因为一切都在Windows 7上完美运行。但是,当我在Win XP上运行它时,关闭最后一帧(打印后)在最后的Destroy()和Exit()语句运行之后的语句,但程序之后没有发生任何事情)我得到'pythonw.exe遇到错误等等等等'。错误报告打印了许多我不知道如何解释的信息,通常结构如“Module#...'somedll.dll' text ...”。

我可以提供所有代码等等。但是希望在XP中只有一些基本的可移植性要求才能让我知道我。

确定粘贴下面的简化代码。一些窗口按顺序弹出,最后一个窗口重复弹出一定次数。我之前没有使用这种框架嵌套编写代码(或使用CallAfter()编写代码)因此肯定存在问题。

import wx
GAME = 5

class Game:
        def __init__(self):
            "various attributes"

class UserFrame ( wx.Frame ):

        def __init__( self, parent, app):
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

            self.app = app

            self.m_button3 = wx.Button( self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
            self.Bind(wx.EVT_BUTTON, self.OnCo, id = self.m_button3.GetId() )

        def OnCo( self, event ):
            self.Close()
            wx.CallAfter(self.nextFrame)
            self.app.Exit()

        def nextFrame(self):
            IntroFrame(None, app).Show()
            app.MainLoop()
            app.Exit()
            print "this prints"

        def __del__( self ):
            pass


class IntroFrame( wx.Frame ):
        def __init__( self, parent, app):
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

            self.app = app
            self.m_button4 = wx.Button( self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
            self.Bind(wx.EVT_BUTTON, self.OnCo, id = self.m_button4.GetId() )

        def OnCo( self, event):
            self.app.myGame = Game()
            wx.CallAfter(self.playGame, self.app.myGame)
            self.Destroy()
            self.app.Exit()

        def playGame(self,myGame):
            apps = []
            for i in range(1,GAME+1):
                    apps.append(CustomApp())
                    PlayerChoice(None, apps[i-1], myGame).Show()
                    apps[i-1].MainLoop()
                    "simple decision tree for game"
                    apps[i-1].Exit()

        def __del__( self ):
            pass


class PlayerChoice( wx.Frame ):

        def __init__( self, parent, app, myGame ):
            self.app = app
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

            self.m_button1 = wx.Button( self, wx.ID_ANY, u"Choice 1", wx.Point( -1,-1 ), wx.DefaultSize, 0 )


            self.Bind(wx.EVT_BUTTON, self.OnCo1, id = self.m_button1.GetId() )


        def OnCo1(self,event):
            self.Close()

        def __del__( self ):
            pass


class CustomApp(wx.App):
    def __init__(self):
        wx.App.__init__(self)
        self.myGame = None
        "some other attributes"


app = CustomApp()
UserFrame(None, app).Show()
app.MainLoop()
print "this doesn't print"
app.Exit()

0 个答案:

没有答案