An Introduction To Embedded Tk (page 8 of 32)

[Previous Page][Next Page][Table of Contents]

6.1 The Decimal Clock Sample Program

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.


**Image**

Figure 6.1: Typical appearance of the decimal clock


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: Like all well-behaved ET programs, the main procedure for the decimal clock concludes by entering the event loop.

[Next Page][Table of Contents]