beetlebug▾
/

option

Adds, reads, and clears the entries of the option database, which gives the default options of new widgets.

option SUBCOMMAND ?ARG ...?

Description

The option database is a list of entries. Each entry has a pattern, a value, and a priority. A new widget looks up each option that the script does not give, by the database name and the database class of the option, such as background and Background. A value of the database replaces the default of the widget and the value of the theme. A widget that exists keeps its options.

A pattern is a list of words with . or * before each word. A word is a widget name, such as ok, or a class, such as Button. The last word is the name or the class of the option. A . matches one level of the widget tree, and a * matches any count of levels. So *Button.background matches the background of each button, and *Frame*Label.foreground matches the foreground of each label inside a frame.

When two entries match, the entry with the higher priority wins. With the same priority, the entry with more . and more names wins, and then the entry that came last.

A subcommand can have a short form, such as option a for option add.

The page of each widget gives the database name and class of each option, such as button.

Subcommands

SubcommandDescription
option addAdds an entry to the option database.
option getGives the value of the option database for an option of a window.
option clearRemoves each entry of the option database.
option readfileAdds the entries of a file to the option database.

Examples

% option add *Button.foreground red
> button .b
> .b cget -foreground
red

% option add *Frame*Label.foreground blue
> frame .f
> label .f.l
> .f.l cget -foreground
blue

Errors

% option
wrong # args: should be "option cmd arg ?arg ...?"
-errorcode TCL WRONGARGS

% option set *x 1
bad option "set": must be add, clear, get, or readfile
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also