beetlebug▾
/

option add

Adds an entry to the option database.

option add PATTERN VALUE ?PRIORITY?

Description

Adds the entry of PATTERN with VALUE. The new widgets after the call get the value. PRIORITY is a number from 0 to 100, or one of the words of the table below. The default is interactive.

Arguments

ArgumentTypeDefaultDescription
PATTERNpatternrequiredThe words of the widget tree and the option, each after a . or a *.
VALUEstringrequiredThe value of the option for each widget that matches.
PRIORITYpriorityinteractiveThe priority of the entry: a number from 0 to 100, or a word.
ValueDescription
widgetDefaultThe priority 20, for the defaults of a set of widgets.
startupFileThe priority 40, for the file of an app.
userDefaultThe priority 60, for the settings of the user.
interactiveThe priority 80, the default.

Returns

An empty string.

Examples

# The entry with the higher priority wins, also when it came first.
% option add *Label.text first 30
> option add *Label.text second 20
> label .l
> .l cget -text
first

# A widget that exists keeps its options.
% option clear
> label .early
> option add *Label.text late
> .early cget -text

Errors

% option add *x 1 101
bad priority level "101": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100
-errorcode NONE

% option add *x 1 high
bad priority level "high": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100
-errorcode NONE

% option add *x
wrong # args: should be "option add pattern value ?priority?"
-errorcode TCL WRONGARGS

Facts

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

See also