ttk::widget(3tk)
β¨ NAME β¨
ttk::widget β Standard options and commands supported by Tk themed widgets π
π DESCRIPTION π
okay so bestie, welcome to the ttk::widget(3tk) page β the Tk Themed Widget one. This manual describes common widget options and commands. no cap.
π STANDARD OPTIONS π
The following options are supported by all Tk themed widgets:
- Command-Line Name:
-classDatabase Name:undefinedDatabase Class:undefinedSpecifies 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.
π¨ bestie, this is a read-only option: it may only be specified when the window is created, and may not be changed with the configure widget command.
- Command-Line Name:
-cursorDatabase Name:cursorDatabase Class:CursorSpecifies the mouse cursor to be used for the widget. SeeTk_GetCursorandcursors(3tk)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. - Command-Line Name:
-takefocusDatabase Name:takeFocusDatabase Class:TakeFocusDetermines 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(3tk)in the Tk reference manual for the full description. - Command-Line Name:
-styleDatabase Name:styleDatabase Class:StyleMay 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(3tk) for more information.
- Command-Line Name:
-xscrollcommandDatabase Name:xScrollCommandDatabase Class:ScrollCommandA 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-xscrollcommandoption 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. - Command-Line Name:
-yscrollcommandDatabase Name:yScrollCommandDatabase Class:ScrollCommandA 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:
- Command-Line Name:
-anchorDatabase Name:anchorDatabase Class:AnchorSpecifies 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). - Command-Line Name:
-compoundDatabase Name:compoundDatabase Class:CompoundSpecifies 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(3tk)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.
- Command-Line Name:
-fontDatabase Name:fontDatabase Class:FontFont to use for the text displayed by the widget. - Command-Line Name:
-foregroundDatabase Name:textColorDatabase Class:TextColorThe widget's foreground color. If unspecified, the theme default is used. - Command-Line Name:
-imageDatabase Name:imageDatabase Class:ImageSpecifies 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 of statespec / 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. - Command-Line Name:
-justifyDatabase Name:justifyDatabase Class:JustifyIf 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). - Command-Line Name:
-paddingDatabase Name:paddingDatabase Class:PaddingSpecifies 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. - Command-Line Name:
-textDatabase Name:textDatabase Class:TextSpecifies a text string to be displayed inside the widget (unless overridden by-textvariablefor the widgets supporting this option). - Command-Line Name:
-textvariableDatabase Name:textVariableDatabase Class:VariableSpecifies the name of a global variable whose value will be used in place of the-textresource. - Command-Line Name:
-underlineDatabase Name:underlineDatabase Class:UnderlineIf 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. - Command-Line Name:
-widthDatabase Name:widthDatabase Class:WidthIf 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. - Command-Line Name:
-wraplengthDatabase Name:wrapLengthDatabase Class:WrapLengthSpecifies 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:
- Command-Line Name:
-placeholderDatabase Name:placeHolderDatabase Class:PlaceHolderSpecifies 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. - Command-Line Name:
-placeholderforegroundDatabase Name:placeHolderForegroundDatabase Class:PlaceHolderForegroundSpecifies the foreground color of the placeholder text.
π COMPATIBILITY OPTIONS π
This option is only available for themed widgets that have βcorrespondingβ traditional Tk widgets.
- Command-Line Name:
-stateDatabase Name:stateDatabase Class:StateMay be set tonormalordisabledto control the disabled state bit.
π bestie, this is a write-only option: setting it changes the widget state, but thestatewidget command does not affect the-stateoption.
π COMMANDS π
Bestie, this is the command menu β every method you can call on a ttk widget. β¨
pathName cget optionβ Hands you back whatever valueoptionis currently set to. πpathName configure ?option? ?value option value ...?β Query or modify the configuration options of the widget. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. Ifoptionis specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If nooptionis specified, returns a list describing all of the available options forpathName. It's giving full configuration control, no cap. πpathName identify element x yβ Returns the name of the element under the point given byxandy, or an empty string if the point does not lie within any element.xandyare pixel coordinates relative to the widget. Some widgets accept otheridentifysubcommands described in these widgets documentation. πpathName instate statespec ?script?β Test the widget's state. Ifscriptis not specified, returns1if the widget state matchesstatespecand0otherwise. Ifscriptis specified, equivalent to:
if {[pathName instate stateSpec]} script
π«Ά
pathName state ?stateSpec?β Modify or inquire widget state. IfstateSpecis present, sets the widget state: for each flag instateSpec, sets the corresponding flag or clears it if prefixed by an exclamation point. Returns a new state spec indicating which flags were changed:
set changes [pathName state spec]
pathName state $changes
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags. State glow-up, periodt. π
pathName styleβ Return the style used by the widget. π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.2and the second element is.6, 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-xscrollcommandoption. πpathName xview indexβ Adjusts the view in the window so that the content given byindexis displayed at the left edge of the window. β¬ οΈpathName xview moveto fractionβ Adjusts the view in the window so that the characterfractionof the way through the content appears at the left edge of the window.Fractionmust be a fraction between 0 and 1. ποΈpathName xview scroll number whatβ This command shifts the view in the window left or right according tonumberandwhat.Numbermust be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0.Whatmust be eitherpagesorunits. Ifwhatispagesthen the view adjusts bynumberscreenfuls. Ifnumberis negative then characters farther to the left become visible; if it is positive then characters farther to the right become visible. Ifwhatisunits, the view adjusts left or right bynumberaverage-width characters on the display. π
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.2and the second element is.6, 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-yscrollcommandoption. πΈpathName yview indexβ Adjusts the view in the window so that the content given byindexis displayed at the top edge of the window. β¬οΈpathName yview moveto fractionβ Adjusts the view in the window so that the itemfractionof the way through the content appears at the top edge of the window.Fractionmust be a fraction between 0 and 1. ποΈpathName yview scroll number whatβ This command shifts the view in the window up or down according tonumberandwhat.Numbermust be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0.Whatmust be eitherpagesorunits. Ifwhatispagesthen the view adjusts bynumberscreenfuls. Ifnumberis negative then items farther to the top become visible; if it is positive then items farther to the bottom become visible. Ifwhatisunits, the view adjusts up or down bynumberaverage-width characters on the display. π
π¦ 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β). β¨disabledβ Widget is disabled under program control (aka βunavailableβ, βinactiveβ). π«focusβ Widget has keyboard focus. π―pressedβ Widget is being pressed (aka βarmedβ in Motif). πselectedβ βOnβ, βtrueβ, or βcurrentβ for things like checkbuttons and radiobuttons. β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. πͺreadonlyβ Widget should not allow user modification. πalternateβ A widget-specific alternate display format. For example, used for checkbuttons and radiobuttons in the βtristateβ or βmixedβ state, and for buttons with-defaultactive. πinvalidβ The widget's value is invalid. (Potential uses: scale widget value out of bounds, entry widget value failed validation.) β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. π¦user1-user6β Freely usable for other purposes. π§
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 is the iconic βturn it back onβ move, iykyk. π
β¨ 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
That little snippet is literally the whole vibe: check state, respect state, flip state. π«Ά
π SEE ALSO π
ttk::intro(3tk), ttk::style(3tk)
π KEYWORDS π
state, configure, option
That's the Tk 8.5 edition of ttk::widget(3tk) β source/version said Tk 8.5, the page is ttk::widget(3tk), and the date? The footer didn't spill it, so we're keeping it mysterious. Stay configured, bestie. πβ¨
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- 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