2 # the next line restarts using wish \
6 # This script generates a counter with start and stop buttons.
8 # RCS: @(#) $Id: timer,v 1.3 2001/10/29 16:23:33 dkf Exp $
10 label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
11 button .start -text Start -command {
14 set startMoment [clock clicks -milliseconds]
16 .stop configure -state normal
17 .start configure -state disabled
20 button .stop -text Stop -state disabled -command {
22 .stop configure -state disabled
23 .start configure -state normal
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
34 global startMoment stopped
35 if {$stopped} {return}
37 set elapsedMS [expr {[clock clicks -milliseconds] - $startMoment}]
38 .counter config -text [format "%.2f" [expr {double($elapsedMS)/1000}]]
41 bind . <Control-c> {destroy .}
42 bind . <Control-q> {destroy .}