home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / timer < prev    next >
Text File  |  1996-04-23  |  900b  |  41 lines

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4.  
  5. # timer --
  6. # This script generates a counter with start and stop buttons.
  7. #
  8. # @(#) timer 1.5 95/09/07 11:13:20
  9.  
  10. label .counter -text 0.00 -relief raised -width 10
  11. button .start -text Start -command {
  12.     if $stopped {
  13.     set stopped 0
  14.     tick
  15.     }
  16. }
  17. button .stop -text Stop -command {set stopped 1}
  18. pack .counter -side bottom -fill both
  19. pack .start -side left -fill both -expand yes
  20. pack .stop -side right -fill both -expand yes
  21.  
  22. set seconds 0
  23. set hundredths 0
  24. set stopped 1
  25.  
  26. proc tick {} {
  27.     global seconds hundredths stopped
  28.     if $stopped return
  29.     after 50 tick
  30.     set hundredths [expr $hundredths+5]
  31.     if {$hundredths >= 100} {
  32.     set hundredths 0
  33.     set seconds [expr $seconds+1]
  34.     }
  35.     .counter config -text [format "%d.%02d" $seconds $hundredths]
  36. }
  37.  
  38. bind . <Control-c> {destroy .}
  39. bind . <Control-q> {destroy .}
  40. focus .
  41.