ttk::style(3tk)

πŸ“¦
version 9.0.4 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

ttk::style β€” the whole entire vibe-manipulation command for the style database, bestie πŸ’…


✨ NOTES ✨

okay so before we even start, there's a whole Tcl'2004 conference presentation that goes with this, and you can find it right here:

https://tktable.sourceforge.net/tile/tile-tcl2004.pdf

go read it, it's giving academic but make it fashion πŸ“šβœ¨


πŸŽ€ DEFINITIONS πŸŽ€

Every single widget gets assigned a style, and that style is what says which elements make up the widget and how they're arranged, plus all the dynamic and default settings for those element options. By default, the style name is literally the same as the widget's class β€” but you can override that with the -style option, no cap.

A theme is a collection of elements and styles that controls the overall look and feel of an application. And the . style? That's the theme root style, the main character, the one all the derived styles are based on. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

The ttk::style command takes the following arguments:

  • ttk::style configure β€” ttk::style configure style ?-option ?value option value...? ?

Sets the default value of the specified option(s) in style. If style doesn't exist yet, don't worry, it gets created. 🫢 If you only pass style and -option, you're asking for the default value of that -option for that style. And if you pass only style? You get the default values for all the options of style. obsessed.

  • ttk::style element β€” ttk::style element args
    • ttk::style element create β€” ttk::style element create elementName type ?args...?

Makes a brand new element in the current theme, of type type. The only cross-platform built-in element type is image (peep ttk_image(3tk)), but themes can define other element types (see Ttk_RegisterElementFactory). And on suitable versions of Windows, there's an element factory registered to create Windows theme elements (see ttk_vsapi(3tk)). slay. πŸͺŸ

  • ttk::style element names

Returns the list of elements defined in the current theme. that's it, that's the whole thing πŸ’–

  • ttk::style element options β€” ttk::style element options element

Returns the list of element's options.

  • ttk::style layout β€” ttk::style layout style ?layoutSpec?

Defines the widget layout for style style. The format of layoutSpec is down in LAYOUTS below, keep scrolling bestie. If you skip layoutSpec, it hands you back the layout specification for style style. πŸ¦‹

  • ttk::style lookup β€” ttk::style lookup style -option ?state ?default??

Returns the value specified for -option in style style while in state state, using the standard lookup rules for element options. state is a list of state names β€” if you omit it, it defaults to all bits off (aka the "normal" state). If the default argument is there, it's used as a fallback value in case no specification for -option is found. And yeah, if style doesn't exist, it gets created. πŸ’«

  • ttk::style map β€” ttk::style map style ?-option { statespec value... }?

Sets the dynamic (state dependent) values of the specified option(s) in style. Each statespec / value pair gets examined in order, and the value for the first matching statespec is the one that wins. πŸ† If style doesn't exist, it's created. If you only pass style and -option, you get the dynamic values for that -option of style. If you pass only style, you get the dynamic values for all the options of style.

  • ttk::style theme β€” ttk::style theme args
    • ttk::style theme create β€” ttk::style theme create themeName ?-parent basedon? ?-settings script...?

Creates a new theme. It is an error if themeName already exists, so don't even try it. 🚫 If -parent is specified, the new theme inherits styles, elements, and layouts from the parent theme basedon. If -settings is present, script gets evaluated in the context of the new theme, exactly like ttk::style theme settings does. πŸ’…

  • ttk::style theme names

Returns a list of every known theme. the whole roster, periodt πŸ“‹

  • ttk::style theme settings β€” ttk::style theme settings themeName script

Temporarily sets the current theme to themeName, evaluates script, then puts the previous theme back. Typically script just defines styles and elements, though honestly arbitrary Tcl code may appear. we love a flexible queen 🌈

  • ttk::style theme styles β€” ttk::style theme styles ?themeName?

Returns a list of all styles in themeName. If themeName is omitted, the current theme is used.

  • ttk::style theme use β€” ttk::style theme use ?themeName?

No argument? You get the name of the current theme. Argument? This command sets the current theme to themeName and refreshes all widgets. glow up in real time ✨


🧚 LAYOUTS 🧚

A layout specifies a list of elements, each one followed by one or more options saying how to arrange that element. The layout mechanism uses a simplified version of the pack geometry manager: you start with an initial cavity, and each element gets allocated a parcel. Then the parcel actually used by the element gets adjusted inside that allocated parcel. Here are the valid options:

  • -children { sublayout... } β€” Specifies a list of elements to place inside the element.
  • -expand boolean β€” Specifies whether the allocated parcel is the entire cavity. If it is, then specifying -side at the same time gets ignored. Defaults to 0.
  • -side side β€” Specifies which side of the cavity to place the element on; one of left, right, top, or bottom. For instance, -side top allocates the parcel along the top of the cavity, with 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 you pass it an empty string, the actual parcel is centered in the allocated parcel. Default is nswe.

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, and it provides the defaults for all its derived styles. On top of the usual options, these . styling options are configurable with ttk::style:

  • -insertofftime amount β€” Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should stay "off" in each blink cycle. If this option is zero, the cursor does not blink at all β€” it's on all the time. Defaults to 300 ms, unless overridden with a RESOURCE_MANAGER property or .Xdefaults file. 😴
  • -insertontime amount β€” Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should stay "on" in each blink cycle. Defaults to 600 ms, unless overridden with a RESOURCE_MANAGER property or .Xdefaults file. πŸ‘€

🌸 SEE ALSO 🌸

ttk::intro(3tk), ttk::widget(3tk), photo(3tk), ttk_image(3tk)


πŸ’œ KEYWORDS πŸ’œ

style, theme, appearance


and that's the whole page bestie!! this one shipped with Tk 8.5 in the 3tk manual, so if anyone asks where you learned all this, tell them you read the docs like a good little scholar πŸŽ€βœ¨ mwah, go style something gorgeous πŸ¦‹πŸ’…

πŸ“¦ where this page comes from