beetlebug

ztk::style

Adds and removes the stylesheets of the app, and reads or sets the theme and the color scheme.

Synopsis

ztk::style add CSS
ztk::style load FILE
ztk::style remove ID
ztk::style diagnostics ID
ztk::style theme ?modern|classic?
ztk::style scheme

Arguments

Name Type Default Meaning
add CSS subcommand Adds a stylesheet from the text CSS.
load FILE subcommand Adds the stylesheet of a file in the folder of the main script. FILE is a relative path with no ...
remove ID subcommand Removes the stylesheet ID.
diagnostics ID subcommand Gives the problems of the parse of stylesheet ID.
theme ?NAME? subcommand modern Sets the look to modern or classic, the same as ttk::style theme use default or classic. With no name, gives the current look.
scheme subcommand Gives the color scheme of the system: light or dark.

Return value

add and load give the id of the stylesheet, such as style1. diagnostics gives a list of {LINE MESSAGE} pairs. theme with no name gives modern or classic. scheme gives light or dark. The other subcommands give an empty string.

Errors

Error When
ztk::style load is not allowed The embedder gave no style folder.
file "FILE" is outside the style folder FILE is empty, starts with /, has .., or leaves the folder.
cannot read "FILE": ERROR The file does not open.
bad style id "X" remove or diagnostics of a word that is no style id.
bad theme "X": must be classic or modern An unknown theme.
bad option "X": must be add, diagnostics, load, remove, scheme, or theme An unknown subcommand.

Platforms

Platform Works
Windows Yes
macOS Yes
Linux, Wayland Yes
Linux, X11 Yes
Web Yes
iOS, Android Yes
Headless Yes

Example

set id [ztk::style add {
    Button.big { font-size: 18px; padding: 10px 20px; }
}]
button .go -text Go
ztk::class .go add big
pack .go
ztk::style diagnostics $id

See also