我正在学习来自http://wiki.wxpython.org/Getting%20Started的教程,我正忙于笔记本示例。在这里,多个面板被添加到一个框架中。它使用以下示例代码:
class ExamplePanel(wx.Panel):
def __init__(self, parent):
[...]
app = wx.App(False)
frame = wx.Frame(None, title="Demo with Notebook")
nb = wx.Notebook(frame)
nb.AddPage(ExamplePanel(nb), "Absolute Positioning")
nb.AddPage(ExamplePanel(nb), "Page Two")
nb.AddPage(ExamplePanel(nb), "Page Three")
frame.Show()
app.MainLoop()
这对我有用。但是,我不想使用标准的 wx.Frame() 作为框架,而是使用我自己的框架(如果我只使用一个面板,框架就可以工作):
class ExampleFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self,parent, title = title)
panel = wx.Panel(self)
self.CreateStatusBar()
# Setting up the menu.
filemenu = wx.Menu()
#wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets
menuAbout = filemenu.Append(wx.ID_ABOUT, "&About", " Information about this program")
menuExit = filemenu.Append(wx.ID_EXIT, "E&xit", " Terminate the program")
# Creating the menubar
menuBar = wx.MenuBar()
menuBar.Append(filemenu, "&miP3") # Adding filemenu to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
# Set events
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
def OnAbout(self, event):
# A message dialoge box with an OK button. wx.OK is a sandard ID in wxWidgets
dlg = wx.MessageDialog(self, "Author: Niek de Klein", "About miP3")
dlg.ShowModal() # show it
dlg.Destroy() # finally destroy it when finished
def OnExit(self, eevent):
self.Close(True) # close the frame
app = wx.App(False)
frame = frame = ExampleFrame(None, title="Demo with Notebook")
nb = wx.Notebook(frame)
nb.AddPage(ExamplePanel(nb), "Absolute Positioning")
nb.AddPage(ExamplePanel(nb), "Page Two")
nb.AddPage(ExamplePanel(nb), "Page Three")
frame.Show()
app.MainLoop()
如何将多个面板添加到我的自定义框架?