This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained. [More info]
The purpose of a
Notebook widget is to provide an
area where the user can select pages of content by clicking on
tabs at the top of the area, like these:
Each time the user clicks on one of these tabs, the widget
will display the child pane
associated with that tab. Typically, each pane will be a
Frame widget, although a pane can be any
The tab for the child pane that is currently showing is referred to as the selected tab.
You will use the
.add() method to attach a new tab, and its related
content. Other methods let you remove or temporarily hide
Each tab has its own set of options that control its
appearance and behavior. These options are described in
Table 51, “Tab options for the ttk
A number of the methods of this widget use the idea of a
to one of the tabs. Different values for a
may be any of:
Integer values refer to the position of the tab: 0 for the first tab, 1 for the second, and so forth.
You can always refer to a tab by using the child widget itself.
A string of the form
"@ refers to the tab that currently contains the point
( relative to the widget. For
example, the string
"@37,0" would specify
the tab containing a point 37 pixels from the left side
of the widget, along the top edge of the tab.
"current" refers to whichever
tab is currently selected.
In a call to the
.index() method, use the string
"end" to determine the current number of tabs
To create a
Notebook widget as the child of
use this constructor:
Table 50. ttk
||The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”.|
||The cursor that will appear when the mouse is over the notebook; see Section 5.8, “Cursors”.|
||The height in pixels to be allocated to the widget.|
||To add some extra space around the outside of the widget, set this option to that amount of space as a dimension.|
||The style to be used in rendering this menubutton; see Section 49, “Using and customizing ttk styles”.|
By default, a ttk|
||The width in pixels to be allocated to the widget.|
Methods on a ttk
.Notebook widget include all
those described in Section 46, “Methods common to all ttk widgets”, plus:
argument is a widget, usually a
wraps the content of one child pane. If
is not one of
Notebook widget's child panes,
is added as
the next available tab, and the keyword arguments
kw define the tab options for the new pane.
These options are defined it Table 51, “Tab options for the ttk
currently hidden pane, that tab will reappear in its
Once you call this method, a few additional key bindings will work:
Control-Tab will select the tab after the one currently selected. If the last tab was currently selected, selection will rotate back to the first tab.
Shift-Control-Tab does the reverse: it moves to the previous tab, wrapping around to the last tab if the first tab was selected.
You can configure a particular hot key that directly
selects a tab. To do this, use the
underline tab options to
underline one of the characters in each tab. Then the
user can jump to a tab by typing Alt-
underlined character on that tab.
If you have multiple
Notebook widgets in
the same application, these features will not work
correctly unless each child pane widget is created with
Notebook widget as the parent.
This method permanently removes the specified
widget's set of tabs.
The tab identified by
is temporarily removed from
the set of visible tabs in the
You may reinstate it by calling the
For a given
, this method returns the numeric index
of the corresponding tab. There is one exception:
if the argument is the string
method will return the total number of tabs.
This method inserts the widget
at the position specified by
any keyword arguments to describe the new tab and pane.
For the keyword options, see Table 51, “Tab options for the ttk
argument may be any of:
"end" to place the new tab after
all the existing tabs.
An existing child widget; in this case the new
inserted just before that existing widget.
If you call this method without an argument, it will return the window name of the widget whose tab is currently displayed.
To display a specific pane in the
call this method with a
as the argument.
.tab(tabId, option=None, **kw)
Use this method either to set tab options for the child
panes described by
, or to find out what options are set for that
child pane. The tab options are described in Table 51, “Tab options for the ttk
If you call the method with no keyword arguments, it will
return a dictionary of the tab options currently in effect
for the pane specified by
To find out the current value of a specific tab option
, call this
method with the argument “
and the method will return the value of that tab option.
To set one or more tab options for the child described
call this method with keyword arguments. For example,
Notebook, this call would change
the text displayed on the first tab:
self.nb.tab(0, text='Crunchy frog')
This method returns a list of the window names of the
Notebook's child panes, in order from first to
Here are the tab options used in the
Table 51. Tab options for the ttk
If you supply both |
Use this option to add extra space around all four sides
of the panel's content. The value is a dimension. For example,
Use this option to specify where the panel content is
positioned if it does not completely fill the panel
area. Values are the same as for the |
To make a graphic image appear on the tab, supply an
image as the value of
this option. Refer to the |
||The text to appear on the tab.|
||If this option has a nonnegative value n, an underline will appear under the character at position n of the text on the tab.|