因此,我的脚本中出现了一组相当复杂的 wxPython 框架。如有必要,我会发布所有代码,但我不知道一定是代码问题,因为一切都在 Windows 7 上完美运行。但是,当我在 Win XP 上运行它时,在关闭最后一帧后(打印最后的 Destroy() 和 Exit() 语句运行后的语句,但之后程序中没有任何反应)我得到一个“pythonw.exe 遇到错误等等”。错误报告打印了很多我不知道如何解释的信息,通常结构类似于“模块#...'somedll.dll'文本...”。
我可以提供所有代码等。但希望在 XP 中对 wxpython 有一些基本的可移植性要求,有人可以了解我。
好的,在下面粘贴一个简化的代码。依次弹出几个窗口,最后一个窗口重复弹出一定次数。我之前没有编写过这种嵌套帧的代码(或使用 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()