2 # the next line restarts using wish \
6 # This script generates a counter with start and stop buttons.
8 # RCS: @(#) $Id: timer,v 1.4 2003/09/30 14:54:30 dkf Exp $
10 package require Tcl
8.4
13 label .counter
-text 0.00 -relief raised
-width 10 -padx 2m
-pady 1m
14 button .start
-text Start
-command {
17 set startMoment
[clock clicks
-milliseconds]
19 .stop configure
-state normal
20 .start configure
-state disabled
23 button .stop
-text Stop
-state disabled
-command {
25 .stop configure
-state disabled
26 .start configure
-state normal
28 pack .counter
-side bottom
-fill both
29 pack .start
-side left
-fill both
-expand yes
30 pack .stop
-side right
-fill both
-expand yes
37 global startMoment stopped
38 if {$stopped} {return}
40 set elapsedMS
[expr {[clock clicks
-milliseconds] - $startMoment}]
41 .counter config
-text [format
"%.2f" [expr {double
($elapsedMS)/1000}]]
44 bind .
<Control-c
> {destroy .
}
45 bind .
<Control-q
> {destroy .
}