home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / library / demos / timer < prev    next >
Encoding:
Tcl/Tk script  |  1993-07-01  |  810 b   |  36 lines

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