=== wx.Listbook === {{http://www.blog.pythonlibrary.org/wp-content/uploads/2009/12/listbookDemo.png}} The Listbook control uses a ListCtrl to instead of tabs to control the notebook. In this case, you can actually use labeled pictures to change tabs. It’s kind of weird, but I think it’s kind of cool too. As with the Choicebook, this control inherits from the !BookCtrlBase and has the same methods. The primary differences seem to lie with the Listbook’s appearance and in its unique set of events. Let’s take a quick peek at my demo to see how to create one! {{{ #!python import images import wx ######################################################################## class TabPanel(wx.Panel): """ This will be the first notebook tab """ #---------------------------------------------------------------------- def __init__(self, parent): """""" wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY) sizer = wx.BoxSizer(wx.VERTICAL) txtOne = wx.TextCtrl(self, wx.ID_ANY, "") txtTwo = wx.TextCtrl(self, wx.ID_ANY, "") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(txtOne, 0, wx.ALL, 5) sizer.Add(txtTwo, 0, wx.ALL, 5) self.SetSizer(sizer) ######################################################################## class ListbookDemo(wx.Listbook): """""" #---------------------------------------------------------------------- def __init__(self, parent): """Constructor""" wx.Listbook.__init__(self, parent, wx.ID_ANY, style= wx.BK_DEFAULT #wx.BK_TOP #wx.BK_BOTTOM #wx.BK_LEFT #wx.BK_RIGHT ) # make an image list using the LBXX images il = wx.ImageList(32, 32) for x in range(3): obj = getattr(images, 'LB%02d' % (x+1)) bmp = obj.GetBitmap() il.Add(bmp) self.AssignImageList(il) pages = [(TabPanel(self), "Panel One"), (TabPanel(self), "Panel Two"), (TabPanel(self), "Panel Three")] imID = 0 for page, label in pages: self.AddPage(page, label, imageId=imID) imID += 1 self.Bind(wx.EVT_LISTBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(wx.EVT_LISTBOOK_PAGE_CHANGING, self.OnPageChanging) #---------------------------------------------------------------------- def OnPageChanged(self, event): old = event.GetOldSelection() new = event.GetSelection() sel = self.GetSelection() print 'OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel) event.Skip() #---------------------------------------------------------------------- def OnPageChanging(self, event): old = event.GetOldSelection() new = event.GetSelection() sel = self.GetSelection() print 'OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel) event.Skip() ######################################################################## class DemoFrame(wx.Frame): """ Frame that holds all other widgets """ #---------------------------------------------------------------------- def __init__(self): """Constructor""" wx.Frame.__init__(self, None, wx.ID_ANY, "Listbook Tutorial", size=(700,400) ) panel = wx.Panel(self) notebook = ListbookDemo(panel) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5) panel.SetSizer(sizer) self.Layout() self.Show() #---------------------------------------------------------------------- if __name__ == "__main__": app = wx.PySimpleApp() frame = DemoFrame() app.MainLoop() }}} The Listbook’s “tab” controls can be set run along any of the sides, just like the wx.Notebook. You can also attach images with the same methods we used in the Notebook example at the beginning. I shortened the code up a bit by putting the panels in a list and looping over it, but other than that, there’s not much more to write about concerning this widget. '''All code was tested on the following:''' * Windows XP, wxPython 2.8.10.1 (unicode), Python 2.5 * Windows Vista, wxPython 2.8.10.1 (unicode), Python 2.5 === For Further Information === * [[http://www.wxpython.org/docs/api/wx.Listbook-class.html|Official wx.Listbook Documentation]] * [[http://wxpython.org/download.php|Official wxPython Demo]] ''Note: The tutorial on this page is a modified version of the tutorial on my [[http://www.blog.pythonlibrary.org/2009/12/03/the-book-controls-of-wxpython-part-1-of-2/|blog]]''