python - wx.DestroyChildren in event handler cause segmentation fault on osx -
the following python code runs fine on windows, cause segmentation fault on osx. suggestions why? not make difference use callafter...
import wx class myframe(wx.frame): def __init__(self): wx.frame.__init__(self, none) self.sizer = wx.boxsizer(wx.vertical) self.sizer.add(wx.statictext(self, -1, 'static text')) self.sizer.add(wx.button(self, -1, 'button')) self.setsizer(self.sizer) self.bind(wx.evt_button, self.on_button) def on_button(self, event): self.sizer.clear() self.destroychildren() app = wx.app() frame = myframe() frame.show() app.mainloop()
it because there still system messages pending destroyed widgets, (mouse motion in case) possibility code run after return event handler try use destroyed widgets (calling methods or accessing attributes.)
using callafter delay destruction solve problem me, version of wxpython using? if doesn't work may want try using wx.calllater instead, small timeout value.
import wx class myframe(wx.frame): def __init__(self): wx.frame.__init__(self, none) self.sizer = wx.boxsizer(wx.vertical) self.sizer.add(wx.statictext(self, -1, 'static text')) self.sizer.add(wx.button(self, -1, 'button')) self.setsizer(self.sizer) self.bind(wx.evt_button, self.on_button) def on_button(self, event): wx.callafter(self.doit) def doit(self): self.sizer.clear() self.destroychildren() app = wx.app() frame = myframe() frame.show() app.mainloop()
Comments
Post a Comment