Ttk Notebook widget manages a collection of windows and displays a single one at a time. Each child window is associated with a tab, which the user may select to change the currently-displayed window.
Options
This widget accepts the following specific options:
Option | Description |
---|---|
height | If present and greater than zero, specifies the desired height of the pane area (not including internal padding or tabs). Otherwise, the maximum height of all panes is used. |
padding | Specifies the amount of extra space to add around the outside of the notebook. The padding is a list up to four length specifications left top right bottom. If fewer than four elements are specified, bottom defaults to top, right defaults to left, and top defaults to left. |
width | If present and greater than zero, specified the desired width of the pane area (not including internal padding). Otherwise, the maximum width of all panes is used. |
Tab Options
There are also specific options for tabs:
Option | Description |
---|---|
state | Either “normal”, “disabled” or “hidden”. If “disabled”, then the tab is not selectable. If “hidden”, then the tab is not shown. |
sticky | Specifies how the child window is positioned within the pane area. Value is a string containing zero or more of the characters “n”, “s”, “e” or “w”. Each letter refers to a side (north, south, east or west) that the child window will stick to, as per the grid() geometry manager. |
padding | Specifies the amount of extra space to add between the notebook and this pane. Syntax is the same as for the option padding used by this widget. |
text | Specifies a text to be displayed in the tab. |
image | Specifies an image to display in the tab. See the option image described in Widget . |
compound | Specifies how to display the image relative to the text, in the case both options text and image are present. See Label Options for legal values. |
underline | Specifies the index (0-based) of a character to underline in the text string. The underlined character is used for mnemonic activation if Notebook.enable_traversal() is called. |
Tab Identifiers
The tab_id present in several methods of ttk.Notebook
may take any of the following forms:
- An integer between zero and the number of tabs
- The name of a child window
- A positional specification of the form “@x,y”, which identifies the tab
- The literal string “current”, which identifies the currently-selected tab
The literal string “end”, which returns the number of tabs (only valid for
Notebook.index()
)
Virtual Events
This widget generates a <
> virtual event after a new tab is selected.ttk.Notebook
class
tkinter.ttk.``Notebook``add
(child, **kw)
Adds a new tab to the notebook.
If window is currently managed by the notebook but hidden, it is restored to its previous position.
See Tab Options for the list of available options.forget
(tab_id)
Removes the tab specified by tab_id, unmaps and unmanages the associated window.hide
(tab_id)
Hides the tab specified by tab_id.
The tab will not be displayed, but the associated window remains managed by the notebook and its configuration remembered. Hidden tabs may be restored with theadd()
command.identify
(x, y)
Returns the name of the tab element at position x, y, or the empty string if none.index
(tab_id)
Returns the numeric index of the tab specified by tab_id, or the total number of tabs if tab_id is the string “end”.insert
(pos, child, **kw)
Inserts a pane at the specified position.
pos is either the string “end”, an integer index, or the name of a managed child. If child is already managed by the notebook, moves it to the specified position.
See Tab Options for the list of available options.select
(tab_id=None)
Selects the specified tab_id.
The associated child window will be displayed, and the previously-selected window (if different) is unmapped. If tab_id is omitted, returns the widget name of the currently selected pane.tab
(tab_id, option=None, **kw)
Query or modify the options of the specific tab_id.
If kw is not given, returns a dictionary of the tab option values. If option is specified, returns the value of that option. Otherwise, sets the options to the corresponding values.tabs
()
Returns a list of windows managed by the notebook.enable_traversal
()
Enable keyboard traversal for a toplevel window containing this notebook.
This will extend the bindings for the toplevel window containing the notebook as follows:Control-Tab: selects the tab following the currently selected one.
- Shift-Control-Tab: selects the tab preceding the currently selected one.
- Alt-K: where K is the mnemonic (underlined) character of any tab, will select that tab.
Multiple notebooks in a single toplevel may be enabled for traversal, including nested notebooks. However, notebook traversal only works properly if all panes have the notebook they are in as master.