Update tk to version 8.5.5
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / timer
blob99e6f4c70425c51f174b463eb37c52b960c3a2a8
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 # RCS: @(#) $Id: timer,v 1.4 2003/09/30 14:54:30 dkf Exp $
10 package require Tcl 8.4
11 package require Tk
13 label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
14 button .start -text Start -command {
15 if {$stopped} {
16 set stopped 0
17 set startMoment [clock clicks -milliseconds]
18 tick
19 .stop configure -state normal
20 .start configure -state disabled
23 button .stop -text Stop -state disabled -command {
24 set stopped 1
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
32 set startMoment {}
34 set stopped 1
36 proc tick {} {
37 global startMoment stopped
38 if {$stopped} {return}
39 after 50 tick
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 .}
46 focus .
48 # Local Variables:
49 # mode: tcl
50 # End: