ttk::style(n)
π NAME π
ttk::style β Manipulate style database. Yup bestie, this is the ttk::style(n) page from the Tk Themed Widget manual, and it's literally all about making your widgets look iconic. π
β¨ SYNOPSIS β¨
ttk::style option ?args?
π NOTES π
There's also a Tcl'2004 conference presentation if you want the deep lore β it's available at https://tktable.sourceforge.net/tile/tile-tcl2004.pdf. No cap, go peek if you're curious. π¦
π§ DEFINITIONS π§
Every widget gets assigned a style, which specifies the set of elements making up the widget and how they're arranged, along with dynamic and default settings for element options. By default, the style name is the same as the widget's class; this may be overridden by the -style option.
A theme is a collection of elements and styles which controls the overall look and feel of an application. The "." style is the theme root style on which derived styles are based. It's giving root energy, honestly. π
π DESCRIPTION π
The ttk::style command takes the following arguments, so buckle up:
ttk::style configure style ?-option ?value option value...? ?
ttk::style configure style ?-option ?value option value...? ?
Sets the default value of the specified option(s) in style. If style does not exist, it is created. If only style and -option are specified, get the default value for option -option of style style. If only style is specified, get the default value for all options of style style. Slay, defaults. β¨
ttk::style element args
ttk::style element create elementName type ?args...?β Creates a new element in the current theme of typetype. The only cross-platform built-in element type isimage(seettk_image(n)) but themes may define other element types (seeTtk_RegisterElementFactory). On suitable versions of Windows an element factory is registered to create Windows theme elements (seettk_vsapi(n)).ttk::style element namesβ Returns the list of elements defined in the current theme.ttk::style element options elementβ Returns the list ofelement's options.
ttk::style layout style ?layoutSpec?
ttk::style layout style ?layoutSpec?
Define the widget layout for style style. See LAYOUTS below for the format of layoutSpec. If layoutSpec is omitted, return the layout specification for style style.
ttk::style lookup style -option ?state ?default??
ttk::style lookup style -option ?state ?default??
Returns the value specified for -option in style style in state state, using the standard lookup rules for element options. state is a list of state names; if omitted, it defaults to all bits off (the "normal" state). If the default argument is present, it is used as a fallback value in case no specification for -option is found. If style does not exist, it is created. Lowkey essential. π«Ά
ttk::style map style ?-option { statespec value... }?
ttk::style map style ?-option { statespec value... }?
Sets dynamic (state dependent) values of the specified option(s) in style. Each statespec / value pair is examined in order; the value corresponding to the first matching statespec is used. If style does not exist, it is created. If only style and -option are specified, get the dynamic values for option -option of style style. If only style is specified, get the dynamic values for all options of style style.
ttk::style theme args
ttk::style theme create themeName ?-parent basedon? ?-settings script... ?β Creates a new theme. It is an error ifthemeNamealready exists. If-parentis specified, the new theme will inherit styles, elements, and layouts from the parent themebasedon. If-settingsis present,scriptis evaluated in the context of the new theme as perttk::style theme settings.ttk::style theme namesβ Returns a list of all known themes.ttk::style theme settings themeName scriptβ Temporarily sets the current theme tothemeName, evaluatescript, then restore the previous theme. Typicallyscriptsimply defines styles and elements, though arbitrary Tcl code may appear.ttk::style theme styles ?themeName?β Returns a list of all styles inthemeName. IfthemeNameis omitted, the current theme is used.ttk::style theme use ?themeName?β Without an argument the result is the name of the current theme. Otherwise this command sets the current theme tothemeName, and refreshes all widgets.
π§© LAYOUTS π§©
A layout specifies a list of elements, each followed by one or more options specifying how to arrange the element. The layout mechanism uses a simplified version of the pack geometry manager: given an initial cavity, each element is allocated a parcel. Then the parcel actually used by the element is adjusted within the allocated parcel. Valid options are:
-children { sublayout... }β Specifies a list of elements to place inside the element.-expand booleanβ Specifies whether the allocated parcel is the entire cavity. If so, simultaneous specification of-sideis ignored. Defaults to0.-side sideβ Specifies which side of the cavity to place the element; one ofleft,right,top, orbottom. For instance,-side topallocates the parcel along the top of the cavity having width and height respectively the width of the cavity and the height of the element. If omitted, the allocated parcel is the entire cavity (same effect as-expand 1).-sticky [nswe]β Specifies the actual parcel position and size inside the allocated parcel. If specified as an empty string then the actual parcel is centered in the allocated parcel. Default isnswe.
For example:
ttk::style layout Horizontal.TScrollbar {
Scrollbar.trough -children {
Scrollbar.leftarrow -side left
Scrollbar.rightarrow -side right
Horizontal.Scrollbar.thumb -side left -sticky ew
}
}
π ROOT STYLE π
The "." theme root style can be configured like any other style, providing defaults for its derived styles. In addition to the usual options, "." styling options configurable with ttk::style are:
-insertofftime amountβ Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should remain"off"in each blink cycle. If this option is zero then the cursor does not blink: it is on all the time. Defaults to300ms, unless overriden with aRESOURCE_MANAGERproperty or.Xdefaultsfile.-insertontime amountβ Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should remain"on"in each blink cycle. Defaults to600ms, unless overriden with aRESOURCE_MANAGERproperty or.Xdefaultsfile.
π SEE ALSO π
ttk::intro(n), ttk::widget(n), photo(n), ttk_image(n) β go read these next, bestie, they're in the group chat too. π
β KEYWORDS β
style, theme, appearance
source/version: Tk 8.5 Β· manual: ttk::style(n) Β· date: not listed on this page (the footer only gives Tk 8.5 and ttk::style(n)) β mwah π
π¦ 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
- nixpkgs unstable: tk 9.1.0
- 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