私はhttp://wiki.wxpython.org/Getting%20Startedのチュートリアルに従っており、ノートブックの例で忙しいです。ここでは、複数のパネルが1つのフレームに追加されます。次のサンプルコードを使用します。
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()を使用する代わりに、独自のwx.Frame()を使用します(フレームは、1つのパネルのみを使用する場合に機能します)。
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()
カスタムフレームに複数のパネルを追加するにはどうすればよいですか?