]> git.zerfleddert.de Git - micropolis/blob - src/tk/library/demos/timer
XINCLUDE: use /usr/X11R6/include everywhere
[micropolis] / src / tk / library / demos / timer
1 #!/usr/local/bin/wish -f
2 #
3 # This script generates a counter with start and stop buttons.
4
5 label .counter -text 0.00 -relief raised -width 10
6 button .start -text Start -command "set stop 0; tick"
7 button .stop -text Stop -command {set stop 1}
8 pack append . .counter {bot fill} .start {left expand fill} \
9 .stop {right expand fill}
10
11 set seconds 0
12 set hundredths 0
13 set stop 0
14
15 proc tick {} {
16 global seconds hundredths stop
17 if $stop return
18 after 20 tick
19 set hundredths [expr $hundredths+2]
20 if {$hundredths >= 100} {
21 set hundredths 0
22 set seconds [expr $seconds+1]
23 }
24 .counter config -text [format "%d.%2d" $seconds $hundredths]
25 }
26
27 bind . <Control-c> {destroy .}
28 bind . <Control-q> {destroy .}
29 focus .
Impressum, Datenschutz