popping a new frame and deleting the old one in wxPython -
i have simple frame button on it. want when press button, close frame , open new one. old 1 needs destroyed while new 1 should have same functionality destroyed frame. want infinite time.
this code wrote:
import wx class subpanel(wx.panel): def __init__(self, parent, value = 2): wx.panel.__init__(self, parent) self.btnpresshere = wx.button(self, -1, "press here") self.value = value hbox = wx.boxsizer() hbox.add(self.btnpresshere, 1, wx.expand) self.setsizer(hbox) if __name__ == "__main__": class screen(wx.frame): def __init__(self, parent): wx.frame.__init__(self, parent, size = (600,600)) panel = wx.panel(self) panel0 = subpanel(panel, 0) box = wx.boxsizer() box.add(panel0, 1, wx.all | wx.expand) panel.setsizer(box) self.centre() self.show(true) app = wx.app(false) screen(none) app.mainloop()
thanks help.
its easy solve, code:
import wx class buttonframe(wx.frame): def __init__(self, value): wx.frame.__init__(self,none) self.btnpresshere = wx.button(self, -1, "press here: " + str(value)) self.btnpresshere.bind(wx.evt_button, self.onpress) # need bind event self.value = value self.centre() self.show() def onpress(self,evt): buttonframe(self.value + 1) self.destroy() # destroy instance if __name__ == "__main__": app = wx.app(false) buttonframe(0) app.mainloop()
remarks:
- if put button on frame area, use of panel , sizers unnecessary.
- the
self.destroy()
call destroy window, after create another.
Comments
Post a Comment