1#!/bin/sh 2# the next line restarts using wish \ 3exec wish "$0" "$@" 4 5# timer -- 6# This script generates a counter with start and stop buttons. 7# 8# SCCS: @(#) timer 1.6 96/02/16 10:49:20 9 10label .counter -text 0.00 -relief raised -width 10 11button .start -text Start -command { 12 if $stopped { 13 set stopped 0 14 tick 15 } 16} 17button .stop -text Stop -command {set stopped 1} 18pack .counter -side bottom -fill both 19pack .start -side left -fill both -expand yes 20pack .stop -side right -fill both -expand yes 21 22set seconds 0 23set hundredths 0 24set stopped 1 25 26proc 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 38bind . <Control-c> {destroy .} 39bind . <Control-q> {destroy .} 40focus . 41