diff options
author | rjohnson <rjohnson@noemail.net> | 1998-04-01 09:51:45 (GMT) |
---|---|---|
committer | rjohnson <rjohnson@noemail.net> | 1998-04-01 09:51:45 (GMT) |
commit | 9c5b7f2b7e472536ed2e7c915ead05e2aa264182 (patch) | |
tree | 8fb30cb152c4dc191be47fa043d2e6f5ea38c7ba /library/demos/timer | |
parent | 1d0efcbe267f2c0eb73869862522fb20fb2d63ca (diff) | |
download | tk-9c5b7f2b7e472536ed2e7c915ead05e2aa264182.zip tk-9c5b7f2b7e472536ed2e7c915ead05e2aa264182.tar.gz tk-9c5b7f2b7e472536ed2e7c915ead05e2aa264182.tar.bz2 |
Initial revision
FossilOrigin-Name: 2bf55ca9aa942b581137b9f474da5ad9c1480de4
Diffstat (limited to 'library/demos/timer')
-rw-r--r-- | library/demos/timer | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/demos/timer b/library/demos/timer new file mode 100644 index 0000000..b2edd11 --- /dev/null +++ b/library/demos/timer @@ -0,0 +1,40 @@ +#!/bin/sh +# the next line restarts using wish \ +exec wish "$0" "$@" + +# timer -- +# This script generates a counter with start and stop buttons. +# +# SCCS: @(#) timer 1.6 96/02/16 10:49:20 + +label .counter -text 0.00 -relief raised -width 10 +button .start -text Start -command { + if $stopped { + set stopped 0 + tick + } +} +button .stop -text Stop -command {set stopped 1} +pack .counter -side bottom -fill both +pack .start -side left -fill both -expand yes +pack .stop -side right -fill both -expand yes + +set seconds 0 +set hundredths 0 +set stopped 1 + +proc tick {} { + global seconds hundredths stopped + if $stopped return + after 50 tick + set hundredths [expr $hundredths+5] + if {$hundredths >= 100} { + set hundredths 0 + set seconds [expr $seconds+1] + } + .counter config -text [format "%d.%02d" $seconds $hundredths] +} + +bind . <Control-c> {destroy .} +bind . <Control-q> {destroy .} +focus . |