Pmw.NoteBook

Name

Pmw.NoteBook() - a set of tabbed pages

Inherits

Pmw.MegaArchetype

Description

A notebook contains a set of tabbed pages. At any one time only one of these pages (the selected page) is visible, with the other pages being hidden "beneath" it. Another page in the notebook may be displayed by clicking on the tab attached to the page. The tabs are displayed along the top edge.

Optionally, the notebook may be displayed without tabs. In this case, another selection widget, such as Pmw.OptionMenu, may be used to select the pages.

This megawidget is derived from Pmw.MegaArchetype (not Pmw.MegaWidget like most other megawidgets), with the hull class being tkinter.Canvas.

Options

Options for this megawidget and its base classes are described below.

arrownavigation
Initialisation option. If true and a tab button has the keyboard focus, then the Left and Right arrow keys can be used to select the page before or after the tab button with the focus. The default is 1.

borderwidth
Initialisation option. The width of the border drawn around each tab and around the selected page. The default is 2.

createcommand
Specifies a function to call when a page is selected for the first time. The function is called with a single argument, which is the name of the selected page, and is called before the raisecommand function. This allows the creation of the page contents to be deferred until the page is first displayed. The default is None.

lowercommand
Specifies a function to call when the selected page is replaced with a new selected page. The function is called with a single argument, which is the name of the previously selected page, and is called before the createcommand or raisecommand functions. The default is None.

pagemargin
Initialisation option. The margin (in pixels) around the selected page inside the notebook's page border. The default is 4.

raisecommand
Specifies a function to call when a new page is selected. The function is called with a single argument, which is the name of the selected page. The default is None.

tabpos
Initialisation option. Specifies the location of the tabs. If 'n', tabs are created for each page and positioned at the top of the notebook. If None, no tabs are created, in which case another selection widget can be used to select pages by calling the selectpage() method. The default is 'n'.

Components

Components created by this megawidget and its base classes are described below.

hull
This acts as the body for the megawidget. The contents of the megawidget are created as canvas items and positioned in the hull using the canvas coordinate system. By default, this component is a tkinter.Canvas.

Dynamic components

Page and tab components are created dynamically by the add() and insert() methods. By default, the pages are of type tkinter.Frame and are created with a component group of Page and the tabs are of type tkinter.Button and are created with a component group of Tab.

Methods

Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manual for its base class Pmw.MegaArchetype. In addition, methods from the tkinter.Canvas class are forwarded by this megawidget to the hull component.

add(pageName, **kw)
Add a page at the end of the notebook. See the insert() method for full details.

delete(*pageNames)
Delete the pages given by pageNames from the notebook. Each of the pageNames may have any of the forms accepted by the index() method.

If the currently selected page is deleted, then the next page, in index order, is selected. If the end page is deleted, then the previous page is selected.

getcurselection()
Return the name of the currently selected page.

index(index, forInsert = 0)
Return the numerical index of the page corresponding to index. This may be specified in any of the following forms:

name
Specifies the page labelled name.

number
Specifies the page numerically, where 0 corresponds to the first page.

Pmw.END
Specifies the last page.

Pmw.SELECT
Specifies the currently selected page.

If forInsert is true, Pmw.END returns the number of pages rather than the index of the last page.

insert(pageName, before = 0, **kw)
Add a page to the notebook as a component named pageName. The page is added just before the page specified by before, which may have any of the forms accepted by the index() method. If tabpos is not None, also create a tab as a component named pageName-tab. Keyword arguments prefixed with page_ or tab_ are passed to the respective constructors when creating the page or tab. If the tab_text keyword argument is not given, the text option of the tab defaults to pageName. If a page is inserted into an empty notebook, the page is selected. To add a page to the end of the notebook, use add(). The method returns the pageName component widget.

nextpage(pageIndex = None)
If pageIndex is None, then select the page after the currently selected page. Otherwise select the page after pageIndex, which may have any of the forms accepted by the index() method.

page(pageIndex)
Return the frame component widget of the page pageIndex, where pageIndex may have any of the forms accepted by the index() method.

pagenames()
Return a list of the names of the pages, in display order.

previouspage(pageIndex = None)
If pageIndex is None, then select the page before the currently selected page. Otherwise select the page before pageIndex, which may have any of the forms accepted by the index() method.

recolorborders()
Change the color of the page and tab borders. This method is required because the borders are created as canvas polygons and hence do not respond to normal color changing techniques, such as Pmw.Color.changecolor().

selectpage(page)
Select page to be the currently selected page. The page will be raised and the previous selected page will be lowered.

setnaturalsize(pageNames = None)
Set the width and height of the notebook to be the maximum requested width and height of the pages specified by pageNames. If pageNames is None, the size of all pages are used to determine the size of the notebook. Otherwise, pageNames must be a list of page names whose sizes are to be used to determine the size of the notebook. This method should be called after all pages and their contents have been created. It calls update_idletasks() so that the width and height of the pages can be determined. This may cause the notebook to flash onto the screen at the default size before resizing to the natural size.

tab(pageIndex)
Return the tab component widget of the page pageIndex, where pageIndex may have any of the forms accepted by the index() method. If tabpos is None, return None.

Example

The image at the top of this manual is a snapshot of the window (or part of the window) produced by the following code.

class Demo:
    def __init__(self, parent):
        # Create and pack the NoteBook.
        notebook = Pmw.NoteBook(parent)
        notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10)

        # Add the "Appearance" page to the notebook.
        page = notebook.add('Appearance')
        notebook.tab('Appearance').focus_set()

        # Create the "Toolbar" contents of the page.
        group = Pmw.Group(page, tag_text = 'Toolbar')
        group.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
        b1 = tkinter.Checkbutton(group.interior(), text = 'Show toolbar')
        b1.grid(row = 0, column = 0)
        b2 = tkinter.Checkbutton(group.interior(), text = 'Toolbar tips')
        b2.grid(row = 0, column = 1)

        # Create the "Startup" contents of the page.
        group = Pmw.Group(page, tag_text = 'Startup')
        group.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
        home = Pmw.EntryField(group.interior(), labelpos = 'w',
            label_text = 'Home page location:')
        home.pack(fill = 'x', padx = 20, pady = 10)

        # Add two more empty pages.
        page = notebook.add('Helpers')
        page = notebook.add('Images')

        notebook.setnaturalsize()

Pmw 2.1 - 31 Dec 2020 - Home
Manual page last reviewed: 30 October 1999