import wx
class Frame1(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
panel = wx.Panel(self)
button = wx.Button(panel, label="跳转到Frame2")
button.Bind(wx.EVT_BUTTON, self.on_button_click)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 20)
panel.SetSizer(sizer)
def on_button_click(self, event):
frame2 = Frame2(self)
frame2.Show()
self.Disable()
class Frame2(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
panel = wx.Panel(self)
button = wx.Button(panel, label="返回到Frame1")
button.Bind(wx.EVT_BUTTON, self.on_button_click)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 20)
panel.SetSizer(sizer)
def on_button_click(self, event):
self.GetParent().Enable()
self.Close()
if __name__ == "__main__":
app = wx.App()
frame1 = Frame1(None)
frame1.Show()
app.MainLoop()
代码在上面,实现了两个页面的跳转,跳转后原来的界面还在,只是被锁定了。
运行后界面出现一个跳转按钮:
跳转后:
这个方案可用于点击主界面菜单后弹出设置界面,填好设置参数后返回主界面。