2 # the next line restarts using wish \
6 # This script generates a counter with start and stop buttons.
8 package require Tcl
8.4
11 label .counter
-text 0.00 -relief raised
-width 10 -padx 2m
-pady 1m
12 button .start
-text Start
-command {
15 set startMoment
[clock clicks
-milliseconds]
17 .stop configure
-state normal
18 .start configure
-state disabled
21 button .stop
-text Stop
-state disabled
-command {
23 .stop configure
-state disabled
24 .start configure
-state normal
26 pack .counter
-side bottom
-fill both
27 pack .start
-side left
-fill both
-expand yes
28 pack .stop
-side right
-fill both
-expand yes
35 global startMoment stopped
36 if {$stopped} {return}
38 set elapsedMS
[expr {[clock clicks
-milliseconds] - $startMoment}]
39 .counter config
-text [format
"%.2f" [expr {double
($elapsedMS)/1000}]]
42 bind .
<Control-c
> {destroy .
}
43 bind .
<Control-q
> {destroy .
}