beetlebug▾
/

ttk::notebook

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

CommandDescription
ttk::notebook addAdds a page with a tab at the end, or shows a hidden tab again.
ttk::notebook insertPuts a page at a place in the row of tabs.
ttk::notebook forgetRemoves a page and its tab from the notebook.
ttk::notebook hideHides a tab and keeps its page in the notebook.
ttk::notebook indexGives the numeric index of a tab.
ttk::notebook selectGives the page of the selected tab, or selects a tab.
ttk::notebook tabGives or sets the options of a tab.
ttk::notebook tabsGives the pages of the notebook in the order of the tabs.
ttk::notebook identifyGives the element or the tab at a point.
ttk::notebook stateGives the state flags of the widget, or turns flags on and off.
ttk::notebook instateTests the state flags of the widget, and runs a script when they match.
ttk::notebook cgetGives the value of an option of the widget.
ttk::notebook configureGives or sets the options of the widget.

Options

OptionTypeDefaultDatabase nameDescription
-classclass nameemptyThe class of the widget for the option database and for the bindings, set only at creation.
-cursorcursor nameemptycursorThe shape of the pointer over the widget.
-heightscreen distance0heightThe height of the area of the pages, in place of the height of the largest page.
-paddinglist of distancesemptypaddingThe space around the page area, inside the border of the notebook.
-stylestyle nameemptystyleThe style of the widget, such as TNotebook or a style of the script such as Accent.TNotebook.
-takefocusboolean, empty, or scriptttk::takefocustakeFocusWhether the Tab key can move the focus to the widget.
-widthscreen distance0widthThe 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.

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
hand2

ztk 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.

ttk::notebook with -width 160 and -height 30-height 30ttk::notebook with -width 160 and -height 60-height 60
Each with -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.

ttk::notebook with -width 160 -height 40 and -padding {}-padding {}ttk::notebook with -width 160 -height 40 and -padding 4-padding 4ttk::notebook with -width 160 -height 40 and -padding 16-padding 16
Each with -width 160 -height 40.
% ttk::notebook .tnbpa -width 200
> ttk::notebook .tnbpa2 -width 200 -padding 5
> expr {[winfo reqwidth .tnbpa2] - [winfo reqwidth .tnbpa]}
10

ztk 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.TNotebook

ztk 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
0

ztk 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.

ttk::notebook with -height 40 and -width 120-width 120ttk::notebook with -height 40 and -width 200-width 200
Each with -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 PIXELS

Returns

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

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also