#!/usr/local/bin/wafe --f Command c topLevel \ label "Goodbye World!" \ callback {puts Goodbye; quit} realize
How does it work?
The first line,
#!/usr/local/bin/wafe --f
tells the host operating system that this
file contains a script to be executed by
WAFE. The --f
switch, which gets
passed to WAFE, tells it that it is
executing commands from a file (rather than
interactively from a terminal, say).
Tcl interprets commands much like a unix shell, by keying on the first word, which decides the interpretation of any remaining arguments on the line.
Thus, "Command" is both the name of particular class of button widget, and the WAFE command to create a widget of that class.
The second line,
Command c topLevel \
tells WAFE to create a "Command" widget with the particular name "c", and to place it on the widget named "topLevel", which is always present. With the exception of the toplevel widgets representing an entire X window, every widget must be explicitly placed on some other widget.
Virtually all WAFE widget-creation commands begin the same way: With the class of widget to be created, followed by the name of the new widget, followed by the parent widget on which to place the new widget.
The slash at the end of the line second line continues the command to the next line: Tcl is a line-oriented language.
Virtually all WAFE widget-creation commands allow an arbitrary number of property-value pairs to be appended to the creation command: These may be thought of as assigning values to fields in the internal widget structure. (In X jargon, they initialize widget "resources".)
Thus, the third line,
label "Goodbye World!" \
may be thought of in C terms as doing
c.label="Goodbye World!";
and the fourth line,
callback {puts Goodbye; quit}
may be thought of in C terms as doing
c.callback="puts Goodbye; quit"
(Tcl uses curly braces as one way of quoting strings).
As you might guess, the label
resource
on a Command widget specifies the text to be
displayed on the button; the callback
resource specifies the Tcl code to
execute when the button is mouseclicked,
where puts
is a Tcl command
which prints a string to stdout
, and
quit
is a Tcl command to shut
down the Tcl (and hence WAFE)
process.