Update tk to version 8.5.11
[msysgit/kirr.git] / mingw / lib / tk8.5 / demos / timer
blob694227f5126c7fd5eb00be4ce80fa76c58e8b682
1 #!/bin/sh
2 # the next line restarts using wish \
3 exec wish "$0" "$@"
5 # timer --
6 # This script generates a counter with start and stop buttons.
8 package require Tcl 8.4
9 package require Tk
11 label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
12 button .start -text Start -command {
13 if {$stopped} {
14 set stopped 0
15 set startMoment [clock clicks -milliseconds]
16 tick
17 .stop configure -state normal
18 .start configure -state disabled
21 button .stop -text Stop -state disabled -command {
22 set stopped 1
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
30 set startMoment {}
32 set stopped 1
34 proc tick {} {
35 global startMoment stopped
36 if {$stopped} {return}
37 after 50 tick
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 .}
44 focus .
46 # Local Variables:
47 # mode: tcl
48 # End: