home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / demos / Tk / timer < prev    next >
Encoding:
Text File  |  2001-10-22  |  1.1 KB  |  47 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. # RCS: @(#) $Id: timer,v 1.2.18.1 2001/10/12 10:56:13 dkf Exp $
  9.  
  10. label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
  11. button .start -text Start -command {
  12.     if {$stopped} {
  13.     set stopped 0
  14.     set startMoment [clock clicks -milliseconds]
  15.     tick
  16.     .stop configure -state normal
  17.     .start configure -state disabled
  18.     }
  19. }
  20. button .stop -text Stop -state disabled -command {
  21.     set stopped 1
  22.     .stop configure -state disabled
  23.     .start configure -state normal
  24. }
  25. pack .counter -side bottom -fill both
  26. pack .start -side left -fill both -expand yes
  27. pack .stop -side right -fill both -expand yes
  28.  
  29. set startMoment {}
  30. set stopped 1
  31.  
  32. proc tick {} {
  33.     global startMoment stopped
  34.     if {$stopped} {return}
  35.     after 50 tick
  36.     set elapsedMS [expr {[clock clicks -milliseconds] - $startMoment}]
  37.     .counter config -text [format "%.2f" [expr {double($elapsedMS)/1000}]]
  38. }
  39.  
  40. bind . <Control-c> {destroy .}
  41. bind . <Control-q> {destroy .}
  42. focus .
  43.  
  44. # Local Variables:
  45. # mode: tcl
  46. # End:
  47.