Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are just lists of tokens separated by spaces. A Tk widget is just its class, the options that help configure it, and the actions that make it do useful things.
To make a widget in Tk, the command is always of the form:
.myApp.controlPanel.okButton
might be the name of a widget.
Once created, the pathname to the widget becomes a new command. This new widget command is the programmer's handle for getting the new widget to perform some action. In C, you'd express this as someAction(fred, someOptions), in C++, you would express this as fred.someAction(someOptions), and in Tk, you say:
Note that the object name, .fred, starts with a dot.
As you'd expect, the legal values for someAction will depend on
the widget's class: .fred disable
works if fred is a
button (fred gets greyed out), but does not work if fred is a label
(disabling of labels is not supported in Tk).
The legal values of someOptions is action dependent. Some
actions, like disable
, require no arguments, others, like
a text-entry box's delete
command, would need arguments
to specify what range of text to delete. (Unfortunately, John
Ousterhout uses the terms "widget command" and "action"
interchangeably (p 154). This usually doesn't cause much confusion in
practice, but it does muddy the waters for the beginner.)