I’m trying to open a new panel after I clicked button. I created a panel with two tabs and each tab has buttons. This button will open a new panel when clicked. However, I faced some problems. This is my code:
import wx
import os
page1 = None;
page2 = None;
class PanelThree(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent)
panel = wx.Panel(self, size = (800, 600))
vbox = wx.BoxSizer(wx.VERTICAL)
button8 = wx.Button(self, label=“Button Two”, pos=(0, 0))
···
**
# the first tab created.
*class PageOne(wx.Panel): *
*def init(self, parent): *
wx.Panel.init(self, parent)
panel = wx.Panel(self, size = (800,600))
vbox = wx.BoxSizer(wx.VERTICAL)
button1 = wx.Button(panel, -1, “Button One”, (0, 20), size = (200, 30))
button1.Bind(wx.EVT_BUTTON, self.onSwitchPanels1)
**
def onSwitchPanels1(self, event):
if self.page1.IsShown():
self.SetTitle(“Panel”)
self.page1.Hide()
self.panel_two.Show()
else:
self.SetTitle(“Panel”)
self.page1.Show()
self.panel_two.Hide()
self.Layout()
# second tab created.
class PageTwo(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent)
panel = wx.Panel(self, size = (800,600))
#self.mypanel = wx.Panel(self, -1, size = (800, 600))
vbox = wx.BoxSizer(wx.VERTICAL)
button7 = wx.Button(panel, -1, “Button A”, (0, 20), size = (200, 30))
#button7.Bind(wx.EVT_BUTTON, parent.onSwitchPanels7)
button8 = wx.Button(panel, -1, “Button B”, (0, 70), size = (200, 30))
#button8.Bind(wx.EVT_BUTTON, parent.onSwitchPanels8)
# the main frame/panel/windows.
class MainFrame(wx.Frame):
def init(self):
self.something = “something”;
wx.Frame.init(self, None,title=“My Panel”, size=(800, 600))
#grid = TableGrid(self)
**
# Here we create a panel and a notebook on the panel
p = wx.Panel(self)
nb = wx.Notebook(p)
global page1,page2;
**
# create the page windows as children of the notebook
page1 = PageOne(nb)
page2 = PageTwo(nb)
# add the pages to the notebook with the label to show on the tab
nb.AddPage(page1, “Tab One”)
nb.AddPage(page2, “Tab Two”)
**
# finally, put the notebook in a sizer for the panel to manage
# the layout
sizer = wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
p.SetSizer(sizer)
**
self.page1 = PageOne(nb)
self.page1.Hide()
self.panel_two = PanelThree(p)
self.panel_two.Hide()
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.page1, 1, wx.EXPAND)
self.sizer.Add(self.panel_two, 1, wx.EXPAND)
#self.SetSizer(self.sizer)
**
if name == “main”:
app = wx.App()
MainFrame().Show()
app.MainLoop()
I’ve tried some solutions but the second panel won’t appear.