SetSelectionまたはChangeSelectionを使用します。これは、私が作成した楽しい小さなスクリプトで、その方法を示しています(注:[次のページ]メニュー項目を使用する前に、いくつかのページを追加する必要があります)。
import random
import wx
########################################################################
class NewPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
color = random.choice(["red", "blue", "green", "yellow"])
self.SetBackgroundColour(color)
########################################################################
class MyNotebook(wx.Notebook):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Notebook.__init__(self, parent)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self,None, title="NoteBooks!")
self.page_num = 1
panel = wx.Panel(self)
self.notebook = MyNotebook(panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.notebook, 1, wx.EXPAND)
panel.SetSizer(sizer)
self.createMenu()
self.Layout()
self.Show()
#----------------------------------------------------------------------
def createMenu(self):
""""""
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
addPageItem = fileMenu.Append(wx.NewId(), "Add Page",
"Adds new page")
nextPageItem = fileMenu.Append(wx.NewId(), "Next Page",
"Goes to next page")
menuBar.Append(fileMenu, "&File")
self.Bind(wx.EVT_MENU, self.onAdd, addPageItem)
self.Bind(wx.EVT_MENU, self.onNext, nextPageItem)
self.SetMenuBar(menuBar)
#----------------------------------------------------------------------
def onAdd(self, event):
""""""
new_page = NewPanel(self.notebook)
self.notebook.AddPage(new_page, "Page %s" % self.page_num)
self.page_num += 1
#----------------------------------------------------------------------
def onNext(self, event):
""""""
number_of_pages = self.notebook.GetPageCount()
page = self.notebook.GetSelection()+1
if page < number_of_pages:
self.notebook.ChangeSelection(page)
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()