wxPython Major Classes-wxPython Notebook Class - wxPython

What is the use of wxPython Notebook Class?

wxPython class library contains various ‘book’ control. A book control allows the user to switch between various panels in a frame. This is especially useful when a large amount of data is to be presented.

Book classes are inherited from wx.BookCtrlBase class. The following type of book controls are available −

  • wx.Notebook
  • wx.Choicebook
  • wx.Listbook
  • wx.Treebook

wx.Notebook widget presents a tabbed control. One Notebook object in a frame has one or more tabs (called Pages), each of them having a panel showing the layout of controls. The user can switch between pages by clicking on the respective tab title.

Notebook class constructor takes familiar parameters as the following

The following style parameters are available for customization of the widget −

Given below are the most commonly used parameters of style.

S.N.

Parameters & Description

1

wx.NB_TOP

Places tabs on the top side

2

wx.NB_LEFT

Places tabs on the left side

3

wx.NB_RIGHT

Places tabs on the right side

4

wx.NB_BOTTOM

Places tabs under the notebook pages instead of above the notebook pages

5

wx.NB_FIXEDWIDTH

All tabs will have the same width

6

wx.NB_MULTILINE

There can be several rows of tabs

Member functions of Notebook class −

Given below are the most commonly used functions of NoteBook.

S.N.

Functions & Description

1

OnSelChange()

Handler function called when the page selection is changed

2

SetPadding()

Sets the amount space around each page's icon and label, in pixels

3

GetSelection()

Returns the currently selected page

4

SetSelection()

Sets the selection to the given page, returning the previous selection

5

AddPage()

Adds a new page

6

DeletePage()

Deletes a page of given index

7

InsertPage()

Inserts a new tab at the given index

8

RemovePage()

Removes the page without deleting

Event binders defined for this class are −

Given below are the most commonly used Events of NoteBook.

S.N.

Events & Description

1

EVT_NOTEBOOK_PAGE_CHANGED()

The page selection was changed

2

EVT_NOTEBOOK_PAGE_CHANGING()

The page selection is about to be changed

Example

The following example deploys a Notebook control in a top level frame.

Two classes based on wx.Panel are designed. The first, puts a multi-line TextCtrl in it.

The second, shows a RadioBox having three radio buttons.

Objects of these two panel classes are added as pages in Notebook on the top level frame.

The complete code is as follows

The above code produces the following output

notebook_demo_output.jpg

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

wxPython Topics