ttk::style
Guide: Styling and themes
Gives and sets the options of the styles and the themes of the themed widgets.
ttk::style SUBCOMMAND ?ARG ...?
Description
A style is a named set of options for the look of a themed widget, such as TButton. A style name of the script adds a prefix and a dot to a base style, such as Accent.TButton, and a widget uses it with -style. A style with no value of an option gets the value from its base style, and the root style . is the base of each style.
configure sets the default value of an option, and map sets values for some states, such as active or disabled. lookup gives the value that applies. A theme is a named set of styles, and theme use changes the theme of each themed widget.
In ztk, CSS draws each widget. configure and map change the look through CSS for the options -foreground, -background, -fieldbackground, -bordercolor, -borderwidth, -relief, -padding, -font, and -indicatorcolor. ztk stores the other options for lookup. layout and element create store their data with no effect on the look. Styling and themes has the CSS of ztk.
Subcommands
| Subcommand | Description |
|---|---|
ttk::style configure | Gives or sets the default values of the options of a style. |
ttk::style map | Gives or sets the values of the options of a style for some states. |
ttk::style lookup | Gives the value of an option of a style that applies in a state. |
ttk::style layout | Gives or sets the layout of the elements of a style. |
ttk::style theme | Lists, changes, and makes the themes. |
ttk::style element | Lists the elements, gives their options, and makes new elements. |
Examples
% ttk::style configure Accent.TButton -foreground white -background #2563eb
> ttk::button .ok -text OK -style Accent.TButton
> ttk::style lookup Accent.TButton -foreground
white
Errors
% ttk::style
wrong # args: should be "ttk::style option ?arg ...?"
-errorcode TCL WRONGARGS
% ttk::style bogus
bad command "bogus": must be configure, map, lookup, layout, theme, or element
-errorcode NONE
Differences from Tcl
configure,map, andlookupchange the look only for the options of the list above, through CSS.layoutandelement createhave no effect on the look.- In
map, a pair with more states wins over an earlier pair with fewer states. Tk 8.6.16 uses the first pair that matches. - The themes
default,clam, andalthave the modern look of ztk. The themeclassichas the look of Tk on X11. - The errors of
ttk::stylehave the error codeNONE, except the errors of a wrong count of arguments ofttk::style,lookup,layout,theme, andelement. Tk 8.6.16 gives a code such asTTK LOOKUP THEMEorTCL WRONGARGS. configure STYLEgives the options in the order of the script. Tk 8.6.16 gives them in another order.layoutaccepts each option of an element with no check.element createaccepts an image spec with no image and a theme that does not exist. Tk 8.6.16 gives an error for each one.theme namesgives a new theme at the end of the list, andelement namesgives a sorted list that starts with an empty name. Tk 8.6.16 gives a new theme at the start, and has no empty name.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1