OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / ALPHALINUX5 / util / ALPHALINUX5 / lib / tk8.3 / demos / timer
1 #!/bin/sh
2 # the next line restarts using wish \
3 exec wish8.3 "$0" "$@"
4
5 # timer --
6 # This script generates a counter with start and stop buttons.
7 #
8 # RCS: @(#) $Id: timer,v 1.2 1998/09/14 18:23:30 stanton Exp $
9
10 label .counter -text 0.00 -relief raised -width 10
11 button .start -text Start -command {
12     if $stopped {
13         set stopped 0
14         tick
15     }
16 }
17 button .stop -text Stop -command {set stopped 1}
18 pack .counter -side bottom -fill both
19 pack .start -side left -fill both -expand yes
20 pack .stop -side right -fill both -expand yes
21
22 set seconds 0
23 set hundredths 0
24 set stopped 1
25
26 proc tick {} {
27     global seconds hundredths stopped
28     if $stopped return
29     after 50 tick
30     set hundredths [expr $hundredths+5]
31     if {$hundredths >= 100} {
32         set hundredths 0
33         set seconds [expr $seconds+1]
34     }
35     .counter config -text [format "%d.%02d" $seconds $hundredths]
36 }
37
38 bind . <Control-c> {destroy .}
39 bind . <Control-q> {destroy .}
40 focus .