ttk::notebook(3tk)
π ttk::notebook β from the ttk::notebook(3tk) manual, Tk Themed Widget, bestie edition π
okay so. sit down. hydrate. because this widget is a whole vibe and you're gonna be obsessed.
β¨ NAME β¨
ttk::notebook β the multi-paned container widget. it's giving "binder full of tabs," it's giving "one thing visible at a time," it's iconic.
β¨ SYNOPSIS β¨
ttk::notebook pathname ?options...?
pathname add window ?options...?
pathname insert index window ?options...?
π¦ DESCRIPTION π¦
A ttk::notebook widget manages a collection of windows and shows exactly one of them at a time. no cap. each content window gets paired up with a tab, and the user can click that tab to swap which window is currently the main character on screen.
so like: many windows, one spotlight. the way that it justβ¦ rotates them. π
πΈ STANDARD OPTIONS πΈ
-class-cursor-takefocus-style
these are the regulars, the ones every themed widget shows up with. for the full tea on what each one does, go read the ttk_widget manual entry. i'm not about to re-explain stuff that's already slaying elsewhere.
π WIDGET-SPECIFIC OPTIONS π
these are the options this widget brought to the party specifically.
-heightβ Command-Line Name:-height; Database Name:height; Database Class:Height.
if you pass it and it's greater than zero, it sets the height you want for the pane area β and lowkey important: that's not counting internal padding or tabs. if you don't pass it (or it's not > 0), the height used is the maximum height across all the panes.
-paddingβ Command-Line Name:-padding; Database Name:padding; Database Class:Padding.
how much extra space to add around the outside of the notebook. it's a list of up to four length specifications, in this order: left top right bottom. if you give fewer than four, the defaults kick in: bottom defaults to top, right defaults to left, and top defaults to left. so, translated:
- three numbers β left, vertical, right padding
- two numbers β horizontal and vertical padding
- one number β same padding all the way around the widget π«Ά
-widthβ Command-Line Name:-width; Database Name:width; Database Class:Width.
if you pass it and it's greater than zero, it sets the width you want for the pane area (again, not including internal padding). otherwise, the width used is the maximum width of all the panes.
π TAB OPTIONS π
these are the options you can set on individual notebook panes. per-tab customization, we love to see it.
-stateβ Command-Line Name:-state; Database Name:state; Database Class:State.
one of normal, disabled or hidden. if it's disabled, the tab can't be selected. if it's hidden, the tab isn't shown at all. π
-stickyβ Command-Line Name:-sticky; Database Name:sticky; Database Class:Sticky.
how the content window sits inside the pane area. the value is a string with zero or more of the characters n, s, e, or w. each letter means a side β north, south, east, or west β and the content window will "stick" to that side, exactly like the grid geometry manager does it.
-paddingβ Command-Line Name:-padding; Database Name:padding; Database Class:Padding.
how much extra space to add between the notebook and this specific pane. syntax works the same as the widget's -padding option. same rules, smaller scale.
-textβ Command-Line Name:-text; Database Name:text; Database Class:Text.
the string shown in the tab. the label. the name tag. π
-imageβ Command-Line Name:-image; Database Name:image; Database Class:Image.
an image to display in the tab. head to ttk_widget(3tk) for the details on that one.
-compoundβ Command-Line Name:-compound; Database Name:compound; Database Class:Compound.
when both -text and -image are present, this says how the image is displayed relative to the text. label(3tk) has the legal values, go check it.
-underlineβ Command-Line Name:-underline; Database Name:underline; Database Class:Underline.
the integer index (0-based, bestie, don't forget) of a character to underline in the text string. and here's why that matters: that underlined character is the one used for mnemonic activation if ttk::notebook::enableTraversal gets called. so yes, the underline is doing actual work.
π TAB IDENTIFIERS π
the tabid argument to the commands below can take any of these 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. so yes, you can do math on them. periodt. β¨
π WIDGET COMMAND π
on top of the standard cget, configure, instate, state and style commands (peep ttk::widget for those), notebook widgets also support these extra commands:
pathname add window ?options...?β adds a new tab to the notebook. the list of available options lives in TAB OPTIONS. ifwindowis currently managed by the notebook but hidden, it gets restored to its previous position. glow-up, reclaimed. π«Άpathname forget tabidβ removes the tab specified bytabid, and unmaps and unmanages the associated window. gone gone.pathname hide tabidβ hides the tab specified bytabid. the tab isn't displayed, but hear me out: the associated window stays managed by the notebook and its configuration is remembered. hidden tabs can be brought back with theaddcommand. it's not a goodbye, it's a pause. πpathname identify component x yβ returns the name of the element under the point given byxandy, or the empty string if there's no component 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, it gets moved to the specified position. see TAB OPTIONS for the list of available options.pathname select ?tabid?β selects the specified tab. the associated content window gets displayed, and the previously-selected window (if it's a different one) is unmapped. if you omittabid, it returns the widget name of the currently selected pane. β¨pathname tab tabid ?-option ?value ...β query or modify the options of a specific tab. if you pass no-option, you get back a dictionary of the tab's option values. if you pass one-option, you get the value of that option. otherwise, it sets the-options to the corresponding values. see TAB OPTIONS for what's available.pathname tabsβ returns the list of windows managed by the notebook, in the index order of their associated tabs.
π§ KEYBOARD TRAVERSAL π§
to turn on keyboard traversal for a toplevel window containing a notebook widget $nb, you just call:
ttk::notebook::enableTraversal $nb
this extends the bindings for the toplevel window containing the notebook, like so:
- Control+Tab selects the tab following the currently selected one.
- Control+Shift+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.
you can enable multiple notebooks in a single toplevel for traversal, nested notebooks included. however β and this is a real one β notebook traversal only works properly if all panes are direct children of the notebook. so don't get cute with the hierarchy, bestie. π
β VIRTUAL EVENTS β
the notebook widget generates a <<NotebookTabChanged>> virtual event after a new tab is selected. so you can listen for the tab-switch moment. obsession-worthy hook, 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
that's a notebook, two tabs, a select, and traversal turned on. chef's kiss. πβ¨
okay that's part one, there's more coming β do not scroll away, we're not done being iconic π
β¨ STYLING OPTIONS β¨
okay so bestie, style o'clock. The class name for a ttk::notebook is TNotebook. The tab has a class name of TNotebook.Tab. not me knowing all the class names by heart.
Dynamic states: active, disabled, selected. that's the whole mood ring.
TNotebook styling options configurable with ttk::style are:
-backgroundcolor β the background color. duh.-bordercolorcolor β the border color. border tea.-darkcolorcolor β the dark color. dark mode energy.-foregroundcolor β the foreground color. foreground tea.-lightcolorcolor β the light color. light mode energy.-paddingpadding β the padding. personal space, but for pixels.-tabmarginspadding β the tab margins. margins, but make it tab.-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. this one is the blueprint.-tabplacementplacement β Specifies the placement (anchor) of the tabs within the tab row or column as a string of length 1 or 2. The first character indicates the side asw,e,n, ors, while the second character (if present) is the sticky bit (specified ass,n,e, orw) within the tab placement. For example, the tab placementwsmeans: attach the west (left) side of each tab to the previous one and align the south (bottom) edges with each other. Similarly, the tab placementsespecifies to attach the south (bottom) side of each tab to the previous one and align the east (right) edges with each other. The default placement depends on the first character of the tab position:wsforn*,wnfors*,neforw*, andnwfore*. the way the compass ate.
TNotebook.Tab styling options configurable with ttk::style are:
-backgroundcolor β the background color. again, but for the tab.-bordercolorcolor β the border color. again, but tab.-compoundcompound β the compound setting. iykyk.-expandpadding β Defines how much the tab grows in size. Usually used with the selected dynamic state.-tabmarginsshould be set appropriately so that there is room for the tab growth. For example, the Ttk library filevistaTheme.tclcontains 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. copy-paste with confidence, bestie.
-fontfont β the font. typography moment.-foregroundcolor β the foreground color. text tea, but tab.-paddingpadding β Some themes use a different padding for the selected tab. For example, the Ttk library fileclamTheme.tclcontains 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. adaptive queen.
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(3tk)grid(3tk)
π KEYWORDS π
panetab
π and that's a wrap! source/version: Tk 8.5, page ttk::notebook(3tk). no date on the footer, just vibes. periodt. π
π¦ where this page comes from
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 2004 Joe English
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms