ttk::notebook(n)
β¨ ttk::notebook(n) β Multi-Paned Container Widget β¨
okay so bestie, this is the manual page for ttk::notebook(n), aka the multi-paned container widget. It's giving very "tabs but make it Tk" energy π
.
πΈ NAME πΈ
ttk::notebook β multi-paned container widget π«Ά
π SYNOPSIS π
ttk::notebook pathname ?options...?
pathname add window ?options...?
pathname insert index window ?options...?
π¦ DESCRIPTION π¦
so a ttk::notebook widget manages a whole collection of windows and shows exactly one at a time, bestie. Each content window is associated with a tab, and the user can select that tab to change which window is currently displayed. iconic behavior honestly β¨.
π STANDARD OPTIONS π
-class-cursor-takefocus-style
see the ttk_widget manual entry for all the details on these standard options π.
π WIDGET-SPECIFIC OPTIONS π
-heightβ command-line name:-height; database name:height; database class:Height. If present and greater than zero, it specifies the desired height of the pane area (not including internal padding or tabs). Otherwise, the maximum height of all panes is used.-paddingβ command-line name:-padding; database name:padding; database class:Padding. Specifies the amount of extra space to add around the outside of the notebook. The padding is a list of up to four length specificationsleft top right bottom. If fewer than four elements are specified,bottomdefaults totop,rightdefaults toleft, andtopdefaults toleft. In other words: a list of three numbers specifies the left, vertical, and right padding; a list of two numbers specifies the horizontal and the vertical padding; a single number specifies the same padding all the way around the widget. periodt π.-widthβ command-line name:-width; database name:width; database class:Width. If present and greater than zero, it specifies the desired width of the pane area (not including internal padding). Otherwise, the maximum width of all panes is used.
π TAB OPTIONS π
The following options may be specified for individual notebook panes:
-stateβ command-line name:-state; database name:state; database class:State. Eithernormal,disabledorhidden. Ifdisabled, then the tab is not selectable. Ifhidden, then the tab is not shown.-stickyβ command-line name:-sticky; database name:sticky; database class:Sticky. Specifies how the content window is positioned within the pane area. Value is a string containing zero or more of the charactersn,s,e, orw. Each letter refers to a side (north, south, east, or west) that the content window will βstickβ to, as per the grid geometry manager.-paddingβ command-line name:-padding; database name:padding; database class:Padding. Specifies the amount of extra space to add between the notebook and this pane. Syntax is the same as for the widget-paddingoption.-textβ command-line name:-text; database name:text; database class:Text. Specifies a string to be displayed in the tab.-imageβ command-line name:-image; database name:image; database class:Image. Specifies an image to display in the tab. Seettk_widget(n)for details.-compoundβ command-line name:-compound; database name:compound; database class:Compound. Specifies how to display the image relative to the text, in the case both-textand-imageare present. Seelabel(n)for legal values.-underlineβ command-line name:-underline; database name:underline; database class:Underline. Specifies the integer index (0-based) of a character to underline in the text string. The underlined character is used for mnemonic activation ifttk::notebook::enableTraversalis called.
π§ TAB IDENTIFIERS π§
The tabid argument to the following commands may take any of the following forms:
- An integer between zero and the number of tabs;
- The name of a content window;
- A positional specification of the form
@x,y, which identifies the tab - The literal string
current, which identifies the currently-selected tab; or: - The literal string
end, which returns the number of tabs (only valid forpathname index).
Indexes support the same simple interpretation as for the command string index, with simple integer index arithmetic and indexing relative to end. no cap β¨.
π WIDGET COMMAND π
In addition to the standard cget, configure, instate, state and style commands (see ttk::widget), notebook widgets support the following additional commands:
pathname add window ?options...?β Adds a new tab to the notebook. See TAB OPTIONS for the list of available options. Ifwindowis currently managed by the notebook but hidden, it is restored to its previous position.pathname forget tabidβ Removes the tab specified bytabid, unmaps and unmanages the associated window.pathname hide tabidβ Hides the tab specified bytabid. 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 theaddcommand.pathname identify component x yβ Returns the name of the element under the point given byxandy, or the empty string if no component is present at that location. The following subcommands are supported:pathname identify element x yβ Returns the name of the element at the specified location.pathname identify tab x yβ Returns the index of the tab at the specified location.
pathname index tabidβ Returns the numeric index of the tab specified bytabid, or the total number of tabs iftabidis the stringend.pathname insert pos subwindow options...β Inserts a pane at the specified position.posis either the stringend, an integer index, or the name of a managed subwindow. Ifsubwindowis already managed by the notebook, moves it to the specified position. See TAB OPTIONS for the list of available options.pathname select ?tabid?β Selects the specified tab. The associated content window will be displayed, and the previously-selected window (if different) is unmapped. Iftabidis omitted, returns the widget name of the currently selected pane.pathname tab tabid ?-option ?value ...β Query or modify the options of the specific tab. If no-optionis specified, returns a dictionary of the tab option values. If one-optionis specified, returns the value of that option. Otherwise, sets the-optionsto the corresponding values. See TAB OPTIONS for the available options.pathname tabsβ Returns the list of windows managed by the notebook, in the index order of their associated tabs.
π KEYBOARD TRAVERSAL π
To enable keyboard traversal for a toplevel window containing a notebook widget $nb, call:
ttk::notebook::enableTraversal $nb
This will extend the bindings for the toplevel window containing the notebook as follows:
- Control-Tab selects the tab following the currently selected one.
- Control-Shift-Tab selects the tab preceding the currently selected one.
- Alt-K, where
Kis 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 are direct children of the notebook. iykyk π«Ά.
β VIRTUAL EVENTS β
The notebook widget generates a <<NotebookTabChanged>> virtual event after a new tab is selected. main character event energy fr fr π«.
πΈ EXAMPLE πΈ
pack [ttk::notebook .nb]
.nb add [frame .nb.f1] -text "First tab"
.nb add [frame .nb.f2] -text "Second tab"
.nb select .nb.f2
ttk::notebook::enableTraversal .nb
β¨ STYLING OPTIONS β¨
okay so this is the glow-up section, bestie π styling is where the notebook gets its whole look together.
The class name for a ttk::notebook is TNotebook. The tab has a class name of TNotebook.Tab.
Dynamic states: active, disabled, selected.
TNotebook styling options configurable with ttk::style are:
-backgroundcolor-bordercolorcolor-darkcolorcolor-foregroundcolor-lightcolorcolor-paddingpadding-tabmarginspadding-tabpositionposition β Specifies the position of the tab row or column as a string of length 1 or 2. The first character indicates the side asn,s,w, ore, while the second character (if present) is the sticky bit (specified asw,e,n, ors) within the tab position. The default position isnfor the aqua theme andnwfor all the other built-in themes.
TNotebook.Tab styling options configurable with ttk::style are:
-backgroundcolor-bordercolorcolor-compoundcompound-expandpadding β Defines how much the tab grows in size. Usually used with theselecteddynamic state.-tabmarginsshould be set appropriately so that there is room for the tab growth.
For example, the Ttk library file vistaTheme.tcl contains the lines
ttk::style configure TNotebook -tabmargins {2 2 2 0}
ttk::style map TNotebook.Tab -expand {selected {2 2 2 2}}
which are valid for the default value nw of the -tabposition style option. For a ttk::notebook style nbStyle defined by
set nbStyle SW.TNotebook
ttk::style configure $nbStyle -tabposition sw
you will have to adapt the above settings as follows:
ttk::style configure $nbStyle -tabmargins {2 0 2 2}
ttk::style map $nbStyle.Tab -expand {selected {2 2 2 2}}
The easiest way to do this is to invoke the library procedure ttk::configureNotebookStyle with $nbStyle as argument, after setting the style's -tabposition option.
-fontfont-foregroundcolor-paddingpadding β Some themes use a different padding for the selected tab.
For example, the Ttk library file clamTheme.tcl contains the lines
ttk::style configure TNotebook.Tab \
-padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map TNotebook.Tab \
-padding {selected {4.5p 3p 4.5p 1.5p}}
which are valid for the default value nw of the -tabposition style option. For a ttk::notebook style having a different tab position you will have to adapt the above settings accordingly. Again, the easiest way to do this is to invoke the library procedure ttk::configureNotebookStyle with the style name as argument, after setting the style's -tabposition option.
Some options are only available for specific themes.
See the ttk::style manual page for information on how to configure ttk styles.
π SEE ALSO
ttk::widget(n), grid(n)
π·οΈ KEYWORDS
pane, tab
and that's the whole page, bestie π«Ά footer says Tk 8.5, and the date slot is just blank, so we're living in mystery ππ
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- Copyright (c) 2004 Joe English
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms