Since Tcl uses strings to communicate with the Tk toolkit, parameters to a
Tk-command must be translated to strings before calling the C function
which implement it. The following conversions are done, depending on the type
of the parameter that must give to the toolkit:
- symbol:
- the print name of the symbol;
- number:
- the external representation of the number expressed in radix 10;
- string:
- no conversion;
- keyword:
- the print name of the keyword where the initial semicolon has
been replaced by a dash (``-'');
- boolean:
- the string "0" if and "1" if
- tk-command:
- the name of the tk-command
- closure:
- the address of the closure using the representation
shown in
.
- otherwise:
- the external ``slashified'' version of the object.
As an example, let us make a button with a label containing the
string "Hello, word". According the original Tk/Tcl documentation,
this can be done in Tcl with
Following the rewriting rules expressed above, this can be done in with
This call defines a new widget object which is stored in the variable .hello. This object can be used as a procedure to customize our button.
For instance, setting the border of this button to 5 pixels wide and its
background to gray would be done in Tcl with
In this would be expressed as
Since keyword colon is replaced by a dash when a Tk-command is called, this
expression could also have been written as: