=== wx.AuiNotebook ===

{{http://www.blog.pythonlibrary.org/wp-content/uploads/2009/12/auiNotebookDemo.png}}

The !AuiNotebook is the only notebook control that does not inherit from the generic !BookCtrlBase. Be sure to study this control’s API to fully understand how to work with it as the AuiNotebook has several methods that are unlike any of the other notebook controls. For example, the !AuiNotebook allows the user to rearrange the tabs, drag the tab into its own area (as you can see from the screenshot above) or even drag the tab from one !AuiNotebook to another. The following code snippet will allow you to do all these things:

{{{
#!python

import wx
import wx.aui

########################################################################
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 DemoPanel(wx.Panel):
    """
    This will be the first notebook tab
    """
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
 
        # create the AuiNotebook instance
        nb = wx.aui.AuiNotebook(self)
 
        # add some pages to the notebook
        pages = [(TabPanel(nb), "Tab 1"),
                 (TabPanel(nb), "Tab 2"),
                 (TabPanel(nb), "Tab 3")]
        for page, label in pages:
            nb.AddPage(page, label)
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(nb, 1, wx.EXPAND)
        self.SetSizer(sizer)
 
########################################################################
class DemoFrame(wx.Frame):
    """
    Frame that holds all other widgets
    """
 
    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, wx.ID_ANY,
                          "AUI-Notebook Tutorial",
                          size=(600,400))
        panel = DemoPanel(self)
        self.Show()
 
#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = DemoFrame()
    app.MainLoop()
}}}

For this simple example, I just created an instance of AuiNotebook by instantiating against wx.aui.AuiNotebook(self) and passing in a wx.Panel. Then I added some pages using the AuiNotebook’s !AddPage() method. Notice also that you can close any tab by clicking on its individual “x”. Now you know how to make your own AuiNotebook!

'''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.aui.AuiNotebook-class.html|wx.aui.AuiNotebook Official 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]]''