ttk::notebook
Guide: Panes and tabs
Makes a themed notebook: a row of tabs over an area that shows one page at a time.
ttk::notebook PATHNAME ?OPTION VALUE ...?
Description
Makes a themed notebook with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. Each page is a widget, often a ttk::frame, that add or insert puts in the notebook with a tab. The notebook is the geometry manager of its pages, and it shows only the page of the selected tab.
A click on a tab selects it. Each change of the selected tab sends the virtual event <<NotebookTabChanged>> to the notebook as an idle callback, after the script that made the change. The first add also selects a tab and sends the event. ttk::notebook::enableTraversal adds the keys Control-Tab and Control-Shift-Tab to move between the tabs.
A tab is named by an index from 0, by end, by current for the selected tab, by the path of its page, or by @X,Y for the tab at a point. The parent of PATHNAME must exist, and PATHNAME must not. The class of the notebook is TNotebook, the name of its style.
Widget commands
| Command | Description |
|---|---|
ttk::notebook add | Adds a page with a tab at the end, or shows a hidden tab again. |
ttk::notebook insert | Puts a page at a place in the row of tabs. |
ttk::notebook forget | Removes a page and its tab from the notebook. |
ttk::notebook hide | Hides a tab and keeps its page in the notebook. |
ttk::notebook index | Gives the numeric index of a tab. |
ttk::notebook select | Gives the page of the selected tab, or selects a tab. |
ttk::notebook tab | Gives or sets the options of a tab. |
ttk::notebook tabs | Gives the pages of the notebook in the order of the tabs. |
ttk::notebook identify | Gives the element or the tab at a point. |
ttk::notebook state | Gives the state flags of the widget, or turns flags on and off. |
ttk::notebook instate | Tests the state flags of the widget, and runs a script when they match. |
ttk::notebook cget | Gives the value of an option of the widget. |
ttk::notebook configure | Gives or sets the options of the widget. |
Options
| Option | Type | Default | Database name | Description |
|---|---|---|---|---|
-class | class name | empty | The class of the widget for the option database and for the bindings, set only at creation. | |
-cursor | cursor name | empty | cursor | The shape of the pointer over the widget. |
-height | screen distance | 0 | height | The height of the area of the pages, in place of the height of the largest page. |
-padding | list of distances | empty | padding | The space around the page area, inside the border of the notebook. |
-style | style name | empty | style | The style of the widget, such as TNotebook or a style of the script such as Accent.TNotebook. |
-takefocus | boolean, empty, or script | ttk::takefocus | takeFocus | Whether the Tab key can move the focus to the widget. |
-width | screen distance | 0 | width | The width of the area of the pages, in place of the width of the widest page. |
-class CLASS
The class of the widget for the option database and for the bindings, set only at creation.
The class name replaces the class of the style, such as TNotebook, in winfo class and in the bind tags of the widget. Give it in the call that makes the widget. A later configure of the option gives an error.
% ttk::notebook .tnbcl -class Fancy
> winfo class .tnbcl
Fancy
% ttk::notebook .tnbcl3
> winfo class .tnbcl3
TNotebook% ttk::notebook .tnbcl2
> .tnbcl2 configure -class Other
attempt to change read-only option
-errorcode NONE-cursor CURSOR
The shape of the pointer over the widget.
Each value side by side: the contact sheet of the cursors
A cursor name of Tk, such as hand2 or xterm. An empty value uses the cursor of the parent.
% ttk::notebook .tnbcu -cursor hand2
> .tnbcu cget -cursor
hand2ztk stores each value of the option with no check.
-height DISTANCE
The height of the area of the pages, in place of the height of the largest page.
A value above 0 sets the height of the page area. 0 makes the area as tall as the tallest page. The row of tabs and the padding add to the requested height.

-height 30
-height 60-width 160.% ttk::notebook .tnbhe -height 100
> ttk::notebook .tnbhe2 -height 200
> expr {[winfo reqheight .tnbhe2] - [winfo reqheight .tnbhe]}
100% ttk::notebook .tnbhe3 -height x
bad screen distance "x"
-errorcode TK VALUE PIXELS-padding PADDING
The space around the page area, inside the border of the notebook.
A list of 1 to 4 distances: left, top, right, and bottom. A missing third value is the first, and a missing fourth value is the second. The padding adds to the requested size.

-padding {}
-padding 4
-padding 16-width 160 -height 40.% ttk::notebook .tnbpa -width 200
> ttk::notebook .tnbpa2 -width 200 -padding 5
> expr {[winfo reqwidth .tnbpa2] - [winfo reqwidth .tnbpa]}
10ztk stores each value at configure, as Tk 8.6.16 does.
-style STYLE
The style of the widget, such as TNotebook or a style of the script such as Accent.TNotebook.
An empty value uses the style TNotebook. A style name of the script ends with the name of the base style, such as Accent.TNotebook, and ttk::style configure and ttk::style map give it its options. A style with no settings looks like its base style.
% ttk::style configure Accent.TNotebook -foreground white
> ttk::notebook .tnbsy -style Accent.TNotebook
> .tnbsy cget -style
Accent.TNotebookztk stores each value of the option with no check, as Tk 8.6.16 does at creation.
-takefocus VALUE
Whether the Tab key can move the focus to the widget.
1 puts the widget in the order of the Tab key, and 0 leaves it out. An empty value uses the default rule of Tk. A script, such as the default ttk::takefocus, runs with the path of the widget appended, and its result is the answer. ttk::takefocus gives 1 when the widget is not disabled and is viewable.
% ttk::notebook .tnbtf -takefocus 0
> .tnbtf cget -takefocus
0ztk stores each value of the option with no check.
-width DISTANCE
The width of the area of the pages, in place of the width of the widest page.
A value above 0 sets the width of the page area. 0 makes the area as wide as the widest page. The padding adds to the requested width.

-width 120
-width 200-height 40.% ttk::notebook .tnbwi -width 200 -padding 5
> winfo reqwidth .tnbwi
212% ttk::notebook .tnbwi2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELSReturns
PATHNAME.
Examples
% ttk::notebook .tabs
> ttk::frame .tabs.general
> ttk::frame .tabs.network
> .tabs add .tabs.general -text General
> .tabs add .tabs.network -text Network
> .tabs select .tabs.network
> list [.tabs tabs] [.tabs index current]
{.tabs.general .tabs.network} 1
% winfo class [ttk::notebook .book]
TNotebook
Errors
# The text of a tab is an option of the tab: see `tab`.
% ttk::notebook .x -text a
unknown option "-text"
-errorcode TK LOOKUP OPTION -text
% ttk::notebook .twice
> ttk::notebook .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS
# The parent .no does not exist.
% ttk::notebook .no.n
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no
% ttk::notebook
wrong # args: should be "ttk::notebook pathName ?-option value ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
-cursoraccepts each value with no check. Tk 8.6.16 gives an error for a cursor name that does not exist.- The errors of
state,instate,identify, and of an unknown widget command have the error codeNONE. Tk 8.6.16 gives a code such asTTK VALUE STATEorTCL LOOKUP INDEX. The error of-underlinehas the codeTCL VALUE NUMBER, where Tk 8.6.16 givesTCL VALUE INTEGER. - The states
activeandhoverare one flag, sostate activeturns on both. - The errors of the widget commands, such as a bad tab or a wrong count of arguments, have the error code
NONE. Tk 8.6.16 gives a code such asTTK SLAVE SPECorTCL WRONGARGS. - The row of tabs has the height of the theme, so the requested height and the place of a page differ from Tk 8.6.16.
identify elementgivestabon a tab, where Tk 8.6.16 can give an inner element such asfocus. - The tab options
-imageand-compoundare stored with no effect on the tab.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1