代码编译正常,只是无法加载第二个面板。我查看了许多有关面板切换的论坛,但似乎都没有帮助。
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
##super(Example, self).__init__(parent, title=title,
## size=(500, #width
## 300)) #height
wx.Frame.__init__(self, None, size=(900,270))
self.InitUI()
self.Centre()
self.Show()
#define User Interface
def InitUI(self):
self.panel1 = wx.Panel(self, -1)
#Menu bar
menubar = wx.MenuBar()
filem = wx.Menu()
editm = wx.Menu()
helpm = wx.Menu()
menubar.Append(filem, '&File')
menubar.Append(editm, '&Edit')
menubar.Append(helpm,'&help')
self.SetMenuBar(menubar)
hbox = wx.BoxSizer(wx.HORIZONTAL)
#buttons
b1 = wx.Button(self.panel1, label='button', size=(300,30), pos=(0,0))
hbox.Add(b1)
b1.Bind(wx.EVT_BUTTON, self.OnB1)
#panel2
self.panel2 = wx.Panel(self.panel1, -1)
self.panel2.Hide()
vbox = wx.BoxSizer(wx.HORIZONTAL)
b2 = wx.Button(self.panel2, label='button2', size=(300,30), pos=(0,0))
vbox.Add(b2)
def OnB1(self, event):
self.panel2.Show()
self.panel1.Hide()
if __name__ == '__main__':
app = wx.App()
Example(None, title='')
app.MainLoop()