Table Of Contents

Previous topic

NonOwnedWindow

Next topic

NotifyEvent

This Page

phoenix_title Notebook

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

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

NotebookPage is a typedef for Window.

styles Window Styles

This class supports the following styles:

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

The styles NB_LEFT, RIGHT and BOTTOM are not supported under Microsoft Windows XP when using visual themes.

events Events Emitted by this Class

Handlers bound for the following event types will receive a BookCtrlEvent parameter.

  • EVT_NOTEBOOK_PAGE_CHANGED: The page selection was changed. Processes a wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED event.
  • EVT_NOTEBOOK_PAGE_CHANGING: The page selection is about to be changed. Processes a wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING event. This event can be vetoed.

phoenix_title Page backgrounds

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 NB_NOPAGETHEME to disable themed drawing for a particular notebook, you can call 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.

See also

BookCtrl , BookCtrlEvent, ImageList,


class_hierarchy Inheritance Diagram

Inheritance diagram for class Notebook

Inheritance diagram of Notebook


appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


method_summary Methods Summary

__init__ Constructs a notebook control.
ChangeSelection Changes the selection for the given page, returning the previous selection.
Create Creates a notebook control.
GetPageImage Returns the image index for the given page.
GetPageText Returns the string for the given page.
GetRowCount Returns the number of rows in the notebook control.
GetSelection Returns the currently selected page, or NOT_FOUND if none was selected.
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 .
InsertPage Inserts a new page at the specified position.
SetPadding Sets the amount of space around each page’s icon and label, in pixels.
SetPageImage Sets the image index for the given page.
SetPageText Sets the text for the given page.
SetSelection Sets the selection for the given page, returning the previous selection.

api Class API



class Notebook(BookCtrlBase)

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

Possible constructors:

Notebook()

Notebook(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
         style=0, name=NotebookNameStr)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Constructs a notebook control.



__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=NotebookNameStr)

Constructs a notebook control.

Note that sometimes you can reduce flicker by passing the CLIP_CHILDREN window style.

Parameters:
  • parent (Window) – The parent window. Must be not None.
  • id (int) – The window identifier.
  • pos (Point) – The window position.
  • size (Size) – The window size.
  • style (long) – The window style. See Notebook.
  • name (string) – The name of the control.





ChangeSelection(self, page)

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

This function behaves as SetSelection but does not generate the page changing events.

See User Generated Events vs Programmatically Generated Events for more information.

Parameters:page (int) –
Return type:int


Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=NotebookNameStr)

Creates a notebook control.

See Notebook for a description of the parameters.

Parameters:
  • parent (Window) –
  • id (int) –
  • pos (Point) –
  • size (Size) –
  • style (long) –
  • name (string) –
Return type:

bool



GetPageImage(self, nPage)

Returns the image index for the given page.

Parameters:nPage (int) –
Return type:int


GetPageText(self, nPage)

Returns the string for the given page.

Parameters:nPage (int) –
Return type:string


GetRowCount(self)

Returns the number of rows in the notebook control.

Return type:int


GetSelection(self)

Returns the currently selected page, or NOT_FOUND if none was selected.

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

Return type:int


GetThemeBackgroundColour(self)

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.

Return type: Colour


InsertPage(self, index, page, text, select=False, imageId=NO_IMAGE)

Inserts a new page at the specified position.

Parameters:
  • index (int) – Specifies the position for the new page.
  • page (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.
Return type:

bool

Returns:

True if successful, False otherwise.

Note

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

See also

AddPage



SetPadding(self, padding)

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

Parameters:padding (Size) –

Note

The vertical padding cannot be changed in wxGTK.



SetPageImage(self, 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) –
  • image (int) –
Return type:

bool



SetPageText(self, page, text)

Sets the text for the given page.

Parameters:
  • page (int) –
  • text (string) –
Return type:

bool



SetSelection(self, page)

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

Notice that the call to this function generates the page changing events, use the ChangeSelection function if you don’t want these events to be generated.

Parameters:page (int) –
Return type:int

See also

GetSelection


Properties



RowCount

See GetRowCount



Selection

See GetSelection and SetSelection



ThemeBackgroundColour

See GetThemeBackgroundColour