wx.Notebook

Inheritance diagram for wx.Notebook:



Description

This class represents a notebook control, which manages multiple windows with associated tabs.

To use the class, create a wx.Notebook object and call AddPage or InsertPage, passing a window to be used as the page. Do not explicitly delete the window for a page that is currently managed by wx.Notebook.

wx.NotebookPage is a typedef for wx.Window.

Themes on Windows XP

On Windows XP, the default theme paints a gradient on the notebook’s pages. If you wish to suppress this theme, for aesthetic or performance reasons, there are three ways of doing it. You can use wx.NB_NOPAGETHEME to disable themed drawing for a particular notebook, you can call wx.SystemOptions.SetOption to disable it for the whole application, or you can disable it for individual pages by using SetBackgroundColour.

To disable themed pages globally:

wx.SystemOptions.SetOption("msw.notebook.themed-background", 0)

Set the value to 1 to enable it again.

To give a single page a solid background that more or less fits in with the overall theme, use:

col = notebook.GetThemeBackgroundColour()

if col.IsOk():
    page.SetBackgroundColour(col)

On platforms other than Windows, or if the application is not using Windows themes, GetThemeBackgroundColour will return an uninitialised colour object, and the above code will therefore work on all platforms.

Window Styles

Window Style Description
wx.NB_TOP Place tabs on the top side.
wx.NB_LEFT Place tabs on the left side.
wx.NB_RIGHT Place tabs on the right side.
wx.NB_BOTTOM Place tabs under instead of above the notebook pages.
wx.NB_FIXEDWIDTH (Windows only) All tabs will have same width.
wx.NB_MULTILINE (Windows only) There can be several rows of tabs.
wx.NB_NOPAGETHEME (Windows only) Display a solid colour on notebook pages, and not a gradient, which can reduce performance.
wx.NB_FLAT (Windows CE only) Show tabs in a flat style.

Event Handling

Event Name Description
wx.EVT_NOTEBOOK_PAGE_CHANGED(id, func) The page selection was changed. Processes a wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED event.
wx.EVT_NOTEBOOK_PAGE_CHANGING(id, func) The page selection is about to be changed. Processes a wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING event. This event can be vetoed.

Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


Properties Summary

Class API

Methods

__init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.NotebookNameStr)

Constructor.

Parameters:


Returns:

wx.Notebook


AddPage(page, text, select=False, imageId=-1)

Adds a new page.

Parameters:

  • page (wx.Window): Specifies the new page.
  • text (string): Specifies the text for the new page.
  • select (bool): Specifies whether the page should be selected.
  • imageId (int): Specifies the optional image index for the new page.

Returns:

bool

Note

Do not delete the page, it will be deleted by the notebook.

Note

The call to this function may generate the page changing events.

See also

InsertPage


AdvanceSelection()
Cycles through the tabs.

Note

The call to this function generates the page changing events.


AssignImageList(imageList)

Sets the image list for the page control and takes ownership of the list.

Parameters:


ChangeSelection(page)

Changes the selection for the given page, returning the previous selection.

Parameters:

  • page (int): The new selection

Returns:

int

Note

The call to this function does not generate the page changing events. This is the only difference with SetSelection.


DeleteAllPages()

Deletes all pages.


Returns:

bool


DeletePage(page)

Deletes the specified page, and the associated window.

Parameters:

  • page (int): The page to delete.

Returns:

bool

Note

The call to this function generates the page changing events.


GetCurrentPage()

Returns the currently selected notebook page or None.


Returns:

wx.Window


GetImageList()

Returns the associated image list.


Returns:

wx.ImageList


GetPage(page)

Returns the window at the given page position.

Parameters:

  • page (int): The index of the page.

Returns:

wx.Window


GetPageCount()

Returns the number of pages in the notebook control.


Returns:

long


GetPageImage(page)

Returns the image index for the given page.

Parameters:

  • page (int): The page index.

Returns:

int


GetPageText(page)

Returns the string for the given page.

Parameters:

  • page (int): The page index.

Returns:

string


GetRowCount()

Returns the number of rows in the notebook control.


Returns:

int


GetSelection()

Returns the currently selected page, or -1 if none was selected.


Returns:

int

Note

Note that this method may return either the previously or newly selected page when called from the wx.EVT_NOTEBOOK_PAGE_CHANGED handler depending on the platform and so wx.NotebookEvent.GetSelection should be used instead in this case.


GetThemeBackgroundColour()

If running under Windows and themes are enabled for the application, this function returns a suitable colour for painting the background of a notebook page, and can be passed to SetBackgroundColour. Otherwise, an uninitialised colour will be returned.


Returns:

wx.Colour


HitTest(pt)

Returns the page/tab which is hit, and flags indicating where using wx.NB_HITTEST flags.

The return value tab is one of the following values:

Tab HitTest Flags Description
wx.BK_HITTEST_NOWHERE There was no tab under this point.
wx.BK_HITTEST_ONICON The point was over an icon (currently wxMSW only).
wx.BK_HITTEST_ONLABEL The point was over a label (currently wxMSW only).
wx.BK_HITTEST_ONITEM The point was over an item, but not on the label or icon.
wx.BK_HITTEST_ONPAGE The point was over a currently selected page, not over any tab. Note that this flag is present only if wx.NOT_FOUND is returned.

Parameters:

  • pt (wx.Point) Specifies the point for the hit test.

Returns:

(tab, where)


InsertPage(index, page, text, select=False, imageId=-1)

Inserts a new page at the specified position.

Parameters:

  • index (long): Specifies the position for the new page.
  • page (wx.Window): Specifies the new page.
  • text (string): Specifies the text for the new page.
  • select (bool): Specifies whether the page should be selected.
  • imageId (int): Specifies the optional image index for the new page.

Returns:

bool

Note

Do not delete the page, it will be deleted by the notebook.

See also

AddPage


RemovePage(page)

Deletes the specified page, without deleting the associated window.

Parameters:

  • page (int): The page index.

Returns:

bool


SendPageChangedEvent(nPageOld, nPageNew=-1)

Parameters:

  • nPageOld (int)
  • nPageNew (int)

SendPageChangingEvent(nPage)

Parameters:

  • nPage (int)

Returns:

bool


SetImageList(imageList)

Sets the image list for the page control. It does not take ownership of the image list, you must delete it yourself.

Parameters:


SetPadding(padding)

Sets the amount of space around each page’s icon and label, in pixels.

Parameters:

Note

The vertical padding cannot be changed in wxGTK.


SetPageImage(page, image)

Sets the image index for the given page. image is an index into the image list which was set with SetImageList.

Parameters:

  • page (int): The page index.
  • image (int): The image index.

Returns:

bool


SetPageSize(size)

Sets the width and height of the pages.

Parameters:

Note

This method is currently not implemented for wxGTK.


SetPageText(page, text)

Sets the text for the given page.

Parameters:

  • page (int): The page index.
  • text (string): The page text.

Returns:

bool


SetSelection(page)

Sets the selection for the given page, returning the previous selection.

Parameters:

  • page (int): The new page index.

Warning

This function is deprecated and should not be used in new code. Please use the ChangeSelection function instead.

Note

The call to this function generates the page changing events.

See also

GetSelection


SetTabSize(sz)

Parameters:


Properties

RowCount
See GetRowCount
ThemeBackgroundColour
See GetThemeBackgroundColour