当我尝试在顶层Frame的EVT_CLOSE事件处理函数中调用self.Close(True)时,它会引发RuntimeError:超出最大递归深度。下面的代码:wxPython wx.Close创建运行时错误
from PicEvolve import PicEvolve
import wx
class PicEvolveFrame(wx.Frame):
def __init__(self, parent, id=-1,title="",pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
name="frame"):
wx.Frame.__init__(self,parent,id,title,pos,size,style,name)
self.panel = wx.ScrolledWindow(self)
self.panel.SetScrollbars(1,1,600,400)
statusBar = self.CreateStatusBar()
menuBar = wx.MenuBar()
menu1 = wx.Menu()
m = menu1.Append(wx.NewId(), "&Initialize", "Initialize population with random images")
menuBar.Append(menu1,"&Tools")
self.Bind(wx.EVT_MENU,self.OnInit,m)
self.Bind(wx.EVT_CLOSE,self.OnClose)
self.SetMenuBar(menuBar)
def OnInit(self, event):
dlg = wx.TextEntryDialog(None,"Enter Population Size:","Population Size")
popSize = 0
if dlg.ShowModal() == wx.ID_OK:
popSize = int(dlg.GetValue())
self.pEvolver = PicEvolve(popSize,(200,200),True)
box = wx.BoxSizer(wx.VERTICAL)
filenames = []
for i in range(popSize):
filenames.append("img"+str(i)+".png")
for fn in filenames:
img = wx.Image(fn,wx.BITMAP_TYPE_ANY)
box.Add(wx.StaticBitmap(self.panel,wx.ID_ANY,wx.BitmapFromImage(img)), 0,wx.BOTTOM)
self.panel.SetSizer(box)
def OnClose(self,event):
self.Close(True)
class PicEvolveApp(wx.App):
def OnInit(self):
self.frame = PicEvolveFrame(parent=None,title="PicEvolve")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == "__main__":
app = PicEvolveApp()
app.MainLoop()
顺便说一句,靠近已经被称为当您关闭在框架上,所以这个回调是没有必要的,除非你想期间_do_东西它。 – iondiode 2010-08-02 20:04:34
嗯..我试着添加Skip(),它仍然返回相同的错误。我把回调放在那里的原因是,当我尝试退出时,窗口关闭,但程序仍在提示符下运行。 – Johnny 2010-08-02 20:48:55
是的,这是因为我把它放在那里仍然是错误的(doh)。实际上,如果我注释掉导入的PicEvolve行,并删除绑定onclose和onClose回调,此代码工作正常。因此,也许在picEvolve模块中的某些内容正在运行init – iondiode 2010-08-03 22:50:56