option(3itcl)
β¨ option(3itcl) β¨
part of the incr Tcl family, bestie π
πΈ NAME πΈ
itcl::option β define options for extendedclass, widget or widgetadaptor
ngl some chunks of this description are "borrowed" from the Tcl extension [snit], because the functionality is mostly identical. credit where credit's due π
β οΈ WARNING! β οΈ
okay so this is new functionality in [incr Tcl] where the API can still change!! like bestie do not build your whole personality on this yet π
π¦ SYNOPSIS π¦
option optionSpec ?defaultValue?
option optionSpec ?options?
π DESCRIPTION π
So the option command is what you use inside an [incr Tcl] extendedclass/widget/widgetadaptor definition to define options. it's giving interior design for your class β¨
In the first form, it defines an option for instances of this type, and optionally gives it an initial value. If you don't specify a defaultValue, the initial value defaults to the empty string β no cap, just "".
An option defined this way is said to be locally defined. The optionSpec is a list defining the option's name, resource name, and class name, like:
option {-font font Font} {Courier 12}
The option name must begin with a hyphen, and must not contain any upper case letters. lowercase only, it's a vibe π
The resource name and class name are optional; if you don't specify them, the resource name defaults to the option name minus the hyphen, and the class name defaults to the resource name with the first letter capitalized. So the following statement is literally equivalent to the previous example:
option -font {Courier 12}
See The Tk Option Database for more info about resource and class names. π«Ά
Options are normally set and retrieved using the standard instance methods configure and cget; and within instance code (method bodies, etc.), option values are available through the options array:
set myfont $itcl_options(-font)
In the second form you can define option handlers (e.g., -configuremethod), then it should probably use configure and cget to access its options to avoid subtle errors. (subtle errors are NOT the moment π)
The option statement may include the following options:
-defaultdefvalue β Defines the option's default value; the option's default value will be""otherwise. so if you skip this, it's empty-string szn πΈ-readonlyβ The option is handled read-only β it can only be set usingconfigureat creation time, i.e., in the type's constructor. after that? hands off bestie π-cgetmethodmethodName β Every locally-defined option may define a-cgetmethod; it is called when the option's value is retrieved using thecgetmethod. Whatever the method's body returns will be the return value of the call tocget.
The named method must take one argument, the option name. For example, this code is equivalent to (though slower than) Itcl's default handling of cget:
option -font -cgetmethod GetOption
method GetOption {option} {
return $itcl_options($option)
}
Note that it's possible for any number of options to share a -cgetmethod. sharing is caring π«Ά
-cgetmethodvarvarName β That is very similar to-cgetmethod, the only difference is, one can define a variable, where to find thecgetmethodduring runtime. β¨ dynamic queen behavior β¨-configuremethodmethodName β Every locally-defined option may define a-configuremethod; it is called when the option's value is set using theconfigureorconfigurelistmethods. It is the named method's responsibility to save the option's value; in other words, the value will not be saved to theitcl_options()array unless the method saves it there. so like, if you forget, it's gone. poof. π
The named method must take two arguments, the option name and its new value. For example, this code is equivalent to (though slower than) Itcl's default handling of configure:
option -font -configuremethod SetOption
method SetOption {option value} {
set itcl_options($option) $value
}
Note that it's possible for any number of options to share a single -configuremethod.
-configuremethodvarvarName β That is very similar to-configuremethod, the only difference is, one can define a variable, where to find theconfiguremethodduring runtime.-validatemethodmethodName β Every locally-defined option may define a-validatemethod; it is called when the option's value is set using theconfigureorconfigurelistmethods, just before the-configuremethod(if any). It is the named method's responsibility to validate the option's new value, and to throw an error if the value is invalid. gatekeeping your own options, iconic honestly π
The named method must take two arguments, the option name and its new value. For example, this code verifies that -flag's value is a valid Boolean value:
option -font -validatemethod CheckBoolean
method CheckBoolean {option value} {
if {![string is boolean -strict $value]} {
error "option $option must have a boolean value."
}
}
Note that it's possible for any number of options to share a single -validatemethod.
-validatemethodvarvarName β That is very similar to-validatemethod, the only difference is, one can define a variable, where to find thevalidatemethodduring runtime.
π KEYWORDS π
option, widget, widgetadaptor, extendedclass
okay that's the whole page, bestie!! this one came from itcl version 4.0, and you can find it filed under option(3itcl) β go forth and define your options, you've absolutely got this πβ¨π¦
π¦ where this page comes from
- debian bookworm: tcl-itcl4-doc 4.2.3-1 Β· BSD-Tcl
- debian trixie: tcl-itcl4-doc 4.3.2-3 Β· BSD-Tcl
- ubuntu jammy: tcl-itcl4-doc 4.2.2-1 Β· BSD-Tcl
- ubuntu noble: tcl-itcl4-doc 4.2.4-1 Β· BSD-Tcl
- ubuntu questing: tcl-itcl4-doc 4.3.2-3
- ubuntu resolute: tcl-itcl4-doc 4.3.5-1 Β· BSD-Tcl
- ubuntu stonking: tcl-itcl4-doc 4.3.8-1 Β· BSD-Tcl
- Copyright (c) 2008 Arnulf Wiedemann
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms