# wx.BookCtrlBase¶

A book control is a convenient way of displaying multiple pages of information, displayed one page at a time.

wxWidgets has five variants of this control:

This abstract class is the parent of all these book controls, and provides their basic interface. This is a pure virtual class so you cannot allocate it directly.

## Class Hierarchy¶

Inheritance diagram for class BookCtrlBase:

## Methods Summary¶

 __init__ Default constructor. AddPage Adds a new page. AdvanceSelection Cycles through the tabs. ChangeSelection Changes the selection to the given page, returning the previous selection. Create Constructs the book control with the given parameters. DeleteAllPages Deletes all pages. DeletePage Deletes the specified page, and the associated window. FindPage Returns the index of the specified tab window or NOT_FOUND if not found. GetCurrentPage Returns the currently selected page or None. GetPage Returns the window at the given page position. GetPageCount Returns the number of pages in the control. GetPageImage Returns the image index for the given page. GetPageText Returns the string for the given page. GetSelection Returns the currently selected page, or NOT_FOUND if none was selected. HitTest Returns the index of the tab at the specified position or NOT_FOUND if none. InsertPage Inserts a new page at the specified position. RemovePage Deletes the specified page, without deleting the associated window. SetPageImage Sets the image index for the given page. SetPageSize Sets the width and height of the pages. SetPageText Sets the text for the given page. SetSelection Sets the selection to the given page, returning the previous selection.

## Class API¶

class wx.BookCtrlBase(Control, WithImages)

Possible constructors:

BookCtrlBase()

BookCtrlBase(parent, winid, pos=DefaultPosition, size=DefaultSize,
style=0, name="")


A book control is a convenient way of displaying multiple pages of information, displayed one page at a time.

### Methods¶

__init__(self, *args, **kw)

__init__ (self)

Default constructor.

__init__ (self, parent, winid, pos=DefaultPosition, size=DefaultSize, style=0, name=””)

Constructs the book control with the given parameters.

See Create for two-step construction.

Parameters
• parent (wx.Window) –

• winid (wx.WindowID) –

• pos (wx.Point) –

• size (wx.Size) –

• style (long) –

• name (string) –

AddPage(self, page, text, select=False, imageId=NO_IMAGE)

Adds a new page.

The page must have the book control itself as the parent and must not have been added to this control previously.

The call to this function will generate the page changing and page changed events if select is True, but not when inserting the very first page (as there is no previous page selection to switch from in this case and so it wouldn’t make sense to e.g. veto such event).

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.

Return type

bool

Returns

True if successful, False otherwise.

Note

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

AdvanceSelection(self, forward=True)

Cycles through the tabs.

The call to this function generates the page changing events.

Parameters

forward (bool) –

ChangeSelection(self, page)

Changes the selection to 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, winid, pos=DefaultPosition, size=DefaultSize, style=0, name="")

Constructs the book control with the given parameters.

Parameters
• parent (wx.Window) –

• winid (wx.WindowID) –

• pos (wx.Point) –

• size (wx.Size) –

• style (long) –

• name (string) –

Return type

bool

DeleteAllPages(self)

Deletes all pages.

Return type

bool

DeletePage(self, page)

Deletes the specified page, and the associated window.

The call to this function generates the page changing events when deleting the currently selected page or a page preceding it in the index order, but it does not send any events when deleting the last page: while in this case the selection also changes, it becomes invalid and for compatibility reasons the control never generates events with the invalid selection index.

Parameters

page (int) –

Return type

bool

FindPage(self, page)

Returns the index of the specified tab window or NOT_FOUND if not found.

Parameters

page (wx.Window) – One of the control pages.

Return type

int

Returns

The zero-based tab index or NOT_FOUND if not found.

New in version 2.9.5.

GetCurrentPage(self)

Returns the currently selected page or None.

Return type

wx.Window

GetPage(self, page)

Returns the window at the given page position.

Parameters

page (int) –

Return type

wx.Window

GetPageCount(self)

Returns the number of pages in the control.

Return type

int

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

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 wx.BookCtrlEvent.GetSelection should be used instead in this case.

Return type

int

HitTest(self, pt)

Returns the index of the tab at the specified position or NOT_FOUND if none.

If flags parameter is not None, the position of the point inside the tab is returned as well.

Parameters

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

Return type

tuple

Returns

( int, flags )

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 (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.

Return type

bool

Returns

True if successful, False otherwise.

Note

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

RemovePage(self, page)

Deletes the specified page, without deleting the associated window.

See DeletePage for a note about the events generated by this function.

Parameters

page (int) –

Return type

bool

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

SetPageSize(self, size)

Sets the width and height of the pages.

Parameters

size (wx.Size) –

Note

This method is currently not implemented for wxGTK.

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 to 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

### Properties¶

CurrentPage

PageCount

Selection