To help illustrate the concepts, this section introduces a
new sample program: the decimal clock.
The decimal clock displays the current time of day as a decimal
number of hours. For instance,
8:30am displays as ``8.500''.
11:15pm shows as ``23.250''.
And so forth.
A screen shot of this program is shown
in figure 6.1.
We'll begin by looking at the main procedure for the decimal clock program.
void main(int argc, char **argv){
Et_Init(&argc, argv);
ET_INSTALL_COMMANDS;
ET(
label .x -bd 2 -relief raised -width 7
pack .x
proc Update {} {
.x config -text [DecimalTime]
after 3600 Update
}
Update
);
Et_MainLoop();
}
As you can see, the main procedure is just a copy of the
program template from section 5, with some
of the comments replaced by actual initialization code.
The first initialization action is to invoke the special ET statement
ET_INSTALL_COMMANDS. Don't worry about what this
does just yet -- we'll return to it a little later.
The second initialization action is a single
ET() function containing 7 lines of Tcl/Tk.
This Tcl/Tk code does three things:
Update that
updates the label widget to show the current time, and then arranges
to call itself again after 0.001 hours (3.6 seconds).
Update procedure once in order to
initialize the text of the label widget, and to start the
periodic updates.