ttk::widget(n)
💖 NAME 💖
okay bestie, welcome to ttk::widget(n) — the Tk Themed Widget manual page. Its whole thing is: Standard options and commands supported by Tk themed widgets. This is the shared toolkit lore, the group chat every themed widget is in. 🫶
🦋 DESCRIPTION 🦋
This manual describes common widget options and commands. That's it — common widget options and commands, no gatekeeping. ✨
✨ STANDARD OPTIONS ✨
The following options are supported by all Tk themed widgets. Universal basics, periodt. 💅
-class— Command-Line Name:-class; Database Name:undefined; Database Class:undefined. Specifies the window class. The class is used when querying the option database for the window's other options, to determine the default bindtags for the window, and to select the widget's default layout and style. This is a read-only option: it may only be specified when the window is created, and may not be changed with theconfigurewidget command. So no late-game edits, bestie. 🚫-cursor— Command-Line Name:-cursor; Database Name:cursor; Database Class:Cursor. Specifies the mouse cursor to be used for the widget. SeeTk_GetCursorandcursors(n)in the Tk reference manual for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget.-takefocus— Command-Line Name:-takefocus; Database Name:takeFocus; Database Class:TakeFocus. Determines whether the window accepts the focus during keyboard traversal. Either0,1, a command prefix (to which the widget path is appended, and which should return0or1), or the empty string. Seeoptions(n)in the Tk reference manual for the full description.-style— Command-Line Name:-style; Database Name:style; Database Class:Style. May be used to specify a custom widget style.
🌸 SCROLLABLE WIDGET OPTIONS 🌸
The following options are supported by widgets that are controllable by a scrollbar. See scrollbar(n) for more information.
-xscrollcommand— Command-Line Name:-xscrollcommand; Database Name:xScrollCommand; Database Class:ScrollCommand. A command prefix, used to communicate with horizontal scrollbars. When the view in the widget's window changes, the widget will generate a Tcl command by concatenating the scroll command and two numbers. Each of the numbers is a fraction between0and1indicating a position in the document;0indicates the beginning, and1indicates the end. The first fraction indicates the first information in the widget that is visible in the window, and the second fraction indicates the information just after the last portion that is visible.
Typically the -xscrollcommand option consists of the path name of a scrollbar widget followed by set, e.g. .x.scrollbar set. This will cause the scrollbar to be updated whenever the view in the window changes.
If this option is set to the empty string (the default), then no command will be executed.
-yscrollcommand— Command-Line Name:-yscrollcommand; Database Name:yScrollCommand; Database Class:ScrollCommand. A command prefix, used to communicate with vertical scrollbars. See the description of-xscrollcommandabove for details.
🎀 LABEL OPTIONS 🎀
The following options are supported by labels, buttons, and other button-like widgets:
-anchor— Command-Line Name:-anchor; Database Name:anchor; Database Class:Anchor. Specifies how the information in the widget is positioned relative to the inner margins. Legal values aren,ne,e,se,s,sw,w,nw, andcenter. See also-justify(for widgets supporting this option).-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. If set to the empty string (the default), the rules described in the "Elements" section ofttk::intro(n)explain which value is actually used. The other valid values are:text— Display text only.image— Display image only.center— Display text centered on top of image.top,bottom,left,right— Display image above, below, left of, or right of the text, respectively.none— Display the image if present, otherwise the text.
-font— Command-Line Name:-font; Database Name:font; Database Class:Font. Font to use for the text displayed by the widget.-foreground— Command-Line Name:-foreground; Database Name:textColor; Database Class:TextColor. The widget's foreground color. If unspecified, the theme default is used.-image— Command-Line Name:-image; Database Name:image; Database Class:Image. Specifies an image to display. This is a list of 1 or more elements. The first element is the default image name. The rest of the list is a sequence ofstatespec/ value pairs as per style map, specifying different images to use when the widget is in a particular state or combination of states. All images in the list should have the same size.-justify— Command-Line Name:-justify; Database Name:justify; Database Class:Justify. If there are multiple lines of text, specifies how the lines are laid out relative to one another. One ofleft,center, orright. See also-anchor(for widgets supporting this option).-padding— Command-Line Name:-padding; Database Name:padding; Database Class:Padding. Specifies the internal padding for the widget. 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 specify the left, vertical, and right padding; a list of two numbers specify the horizontal and the vertical padding; a single number specifies the same padding all the way around the widget.-text— Command-Line Name:-text; Database Name:text; Database Class:Text. Specifies a text string to be displayed inside the widget (unless overridden by-textvariablefor the widgets supporting this option).-textvariable— Command-Line Name:-textvariable; Database Name:textVariable; Database Class:Variable. Specifies the name of a global variable whose value will be used in place of the-textresource.-underline— Command-Line Name:-underline; Database Name:underline; Database Class:Underline. If set, specifies the integer index (0-based) of a character to underline in the text string.endcorresponds to the last character,end-1to the before last character, and so on. The underlined character is used for mnemonic activation.-width— Command-Line Name:-width; Database Name:width; Database Class:Width. If greater than zero, specifies how much space, in character widths, to allocate for the text label. If less than zero, specifies a minimum width. If zero or unspecified, the natural width of the text label is used. Note that some themes may specify a non-zero-widthin the style.-wraplength— Command-Line Name:-wraplength; Database Name:wrapLength; Database Class:WrapLength. Specifies the maximum line length. The value may have any of the forms acceptable toTk_GetPixels. If this option is less than or equal to zero, then automatic wrapping is not performed; otherwise the text is split into lines such that no line is longer than the specified value.
🌈 ENTRY OPTIONS 🌈
The following options are supported by entry, spinbox and combobox:
-placeholder— Command-Line Name:-placeholder; Database Name:placeHolder; Database Class:PlaceHolder. Specifies a help text string to display if no text is otherwise displayed, that is when the widget is empty. The placeholder text is displayed using the values of the-font,-justifyand-placeholderforegroundoptions.-placeholderforeground— Command-Line Name:-placeholderforeground; Database Name:placeHolderForeground; Database Class:PlaceHolderForeground. Specifies the foreground color of the placeholder text.
💜 COMPATIBILITY OPTIONS 💜
This option is only available for themed widgets that have “corresponding” traditional Tk widgets.
-state— Command-Line Name:-state; Database Name:state; Database Class:State. May be set tonormalordisabledto control the disabled state bit. This is a write-only option: setting it changes the widget state, but thestatewidget command does not affect the-stateoption.
💅 COMMANDS 💅
okay bestie, this is the part where the widget actually does stuff. every command below is called on pathName, aka your widget’s path. slay.
pathName cget option
returns the current value of the configuration option named by option. that’s it. she’s simple, she’s direct, she’s giving “just tell me the value.” ✨
pathName configure ?option? ?value option value ...?
query or modify the widget’s configuration options, bb. if you pass one or more option-value pairs, the command changes those widget option(s) to the given value(s), and then it returns an empty string.
if you give option with no value, it returns a list describing that named option. the elements of that list are, in order: option name, database name, database class, default value, and current value. if you pass no option at all, it returns a list describing all the available options for pathName. full inventory energy. 🎀
pathName identify element x y
returns the name of the element under the point given by x and y, or an empty string if that point does not lie within any element. x and y are pixel coordinates relative to the widget. some widgets accept other identify subcommands described in those widgets’ documentation. iykyk. 🔍
pathName instate statespec ?script?
test the widget’s state. if script is not specified, it returns 1 if the widget state matches statespec and 0 otherwise. if script is specified, it’s equivalent to:
if {[pathName instate stateSpec]} script
so like… conditionally run your little script based on the state. periodt. 💅
pathName state ?stateSpec?
modify or inquire about widget state. if stateSpec is present, it sets the widget state: for each flag in stateSpec, it sets the corresponding flag, or clears it if the flag is prefixed by an exclamation point.
it returns a new state spec indicating which flags were changed:
set changes [pathName state spec]
pathName state $changes
that pair will restore pathName to the original state. cute little undo button behavior, no cap. if stateSpec is not specified, it returns a list of the currently-enabled state flags. 🫶
pathName style
returns the style used by the widget. that’s the whole command. she said “my style is my identity” and honestly? iconic. 👑
pathName xview args
this command is used to query and change the horizontal position of the content in the widget’s window. it can take any of the following forms:
pathName xview
returns a list containing two elements. each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window.
for example, if the first element is .2 and the second element is .6, then 20% of the widget’s content is off-screen to the left, the middle 40% is visible in the window, and 40% of the content is off-screen to the right. these are the same values passed to scrollbars via the -xscrollcommand option. math girlie behavior. 🌸
pathName xview index
adjusts the view in the window so that the content given by index is displayed at the left edge of the window. left edge. got it. 💖
pathName xview moveto fraction
adjusts the view in the window so that the character fraction of the way through the content appears at the left edge of the window. fraction must be a fraction between 0 and 1. okayyyyy fractional positioning. ✨
pathName xview scroll number what
this command shifts the view in the window left or right according to number and what.
number must be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0.
what must be either pages or units.
- if
whatispages, then the view adjusts bynumberscreenfuls. - if
numberis negative, then characters farther to the left become visible. - if it is positive, then characters farther to the right become visible.
- if
whatisunits, the view adjusts left or right bynumberaverage-width characters on the display.
bestie note: “rounded away from 0” is doing real work there. don’t sleep on it. 😭
pathName yview args
this command is used to query and change the vertical position of the content in the widget’s window. it can take any of the following forms:
pathName yview
returns a list containing two elements. each element is a real fraction between 0 and 1; together they describe the vertical span that is visible in the window.
for example, if the first element is .2 and the second element is .6, then 20% of the widget’s content is off-screen to the top, the middle 40% is visible in the window, and 40% of the content is off-screen to the bottom. these are the same values passed to scrollbars via the -yscrollcommand option. vertical math, same slay. 🦋
pathName yview index
adjusts the view in the window so that the content given by index is displayed at the top edge of the window. top edge supremacy. ⭐
pathName yview moveto fraction
adjusts the view in the window so that the item fraction of the way through the content appears at the top edge of the window. fraction must be a fraction between 0 and 1. yes bestie, item fraction here. read the original closely. 📖
pathName yview scroll number what
this command shifts the view in the window up or down according to number and what.
number must be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0.
what must be either pages or units.
- if
whatispages, then the view adjusts bynumberscreenfuls. - if
numberis negative, then items farther to the top become visible. - if it is positive, then items farther to the bottom become visible.
- if
whatisunits, the view adjusts up or down bynumberaverage-width characters on the display.
same rounding rules, same energy. don’t let the float-to-integer conversion catch you lacking. 💀
🎀 WIDGET STATES 🎀
the widget state is a bitmap of independent state flags. widget state flags include:
active— the mouse cursor is over the widget, and pressing a mouse button will cause some action to occur. aka “prelight” (Gnome), “hot” (Windows), “hover”. she’s hover-adjacent and ready. 🖱️disabled— the widget is disabled under program control. aka “unavailable”, “inactive”. not today, bestie. 🚫focus— the widget has keyboard focus. main character keyboard energy. ⌨️pressed— the widget is being pressed. aka “armed” in Motif. don’t poke her unless you mean it. 💅selected— “On”, “true”, or “current” for things like checkbuttons and radiobuttons. she said yes. ✅background— Windows and the Mac have a notion of an “active” or foreground window. thebackgroundstate is set for widgets in a background window, and cleared for those in the foreground window. window politics, honestly. 🪟readonly— the widget should not allow user modification. look, don’t touch. 🙈alternate— a widget-specific alternate display format. for example, used for checkbuttons and radiobuttons in the “tristate” or “mixed” state, and for buttons with-default active. alternate universe aesthetic. 🌈invalid— the widget’s value is invalid. potential uses: scale widget value out of bounds, entry widget value failed validation. she’s not okay, and that’s valid. 😭hover— the mouse cursor is within the widget. this is similar to theactivestate; it is used in some themes for widgets that provide distinct visual feedback for the active widget in addition to the active element within the widget. subtle, but iconic. 🦋user1–user6— freely usable for other purposes. your custom little state flags. go off. 🫶
a state specification or stateSpec is a list of state names, optionally prefixed with an exclamation point (!) indicating that the bit is off. so !disabled means “not disabled,” bestie. exclamation point is the unofficial “off” girlie. 💅
✨ EXAMPLES ✨
set b [ttk::button .b]
# Disable the widget:
$b state disabled
# Invoke the widget only if it is currently pressed and enabled:
$b instate {pressed !disabled} { .b invoke }
# Reenable widget:
$b state !disabled
look at her go. state, instate, state again. we love a conditional little button moment. 🔥
👀 SEE ALSO 👀
ttk::intro(n), ttk::style(n)
go read those too, bestie. cross-referencing is self-care. 💖
🔑 KEYWORDS 🔑
state, configure, option
mwah 💋 that’s the whole page, bb. source/version: Tk 8.5; page: ttk::widget(n); date: the footer didn’t show one, and i’m not out here inventing lore. 🫶✨
📦 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