option
Guide: Styling and themes
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
| Subcommand | Description |
|---|---|
option add | Adds an entry to the option database. |
option get | Gives the value of the option database for an option of a window. |
option clear | Removes each entry of the option database. |
option readfile | Adds 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
- The error of a line with no colon in
option readfiledoes not give the number of the line. Tk 8.6.16 givesmissing colon on line 1. - The errors have the
-errorcodeNONE, except a wrong count of arguments. Tk 8.6.16 gives codes such asTCL LOOKUP INDEX optionandTK VALUE PRIORITY.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1