summaryrefslogtreecommitdiffstats
path: root/library/demos/timer
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2001-10-29 16:23:32 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2001-10-29 16:23:32 (GMT)
commit0f7f254616e3bbed160bf140e85cce32d98f30bc (patch)
tree8a5f5fa5cf16889cdca31d56195ee53ffdaffa3f /library/demos/timer
parent4430b6a1941111541c5adea2408b1b05bf7f6c14 (diff)
downloadtk-0f7f254616e3bbed160bf140e85cce32d98f30bc.zip
tk-0f7f254616e3bbed160bf140e85cce32d98f30bc.tar.gz
tk-0f7f254616e3bbed160bf140e85cce32d98f30bc.tar.bz2
Improvements to the demo scripts, mostly up-ported from 8.3.4
Diffstat (limited to 'library/demos/timer')
-rw-r--r--library/demos/timer35
1 files changed, 21 insertions, 14 deletions
diff --git a/library/demos/timer b/library/demos/timer
index 5ac504c..5255403 100644
--- a/library/demos/timer
+++ b/library/demos/timer
@@ -5,36 +5,43 @@ exec wish "$0" "$@"
# timer --
# This script generates a counter with start and stop buttons.
#
-# RCS: @(#) $Id: timer,v 1.2 1998/09/14 18:23:30 stanton Exp $
+# RCS: @(#) $Id: timer,v 1.3 2001/10/29 16:23:33 dkf Exp $
-label .counter -text 0.00 -relief raised -width 10
+label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
button .start -text Start -command {
- if $stopped {
+ if {$stopped} {
set stopped 0
+ set startMoment [clock clicks -milliseconds]
tick
+ .stop configure -state normal
+ .start configure -state disabled
}
}
-button .stop -text Stop -command {set stopped 1}
+button .stop -text Stop -state disabled -command {
+ set stopped 1
+ .stop configure -state disabled
+ .start configure -state normal
+}
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 startMoment {}
+
set stopped 1
proc tick {} {
- global seconds hundredths stopped
- if $stopped return
+ global startMoment 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]
+ set elapsedMS [expr {[clock clicks -milliseconds] - $startMoment}]
+ .counter config -text [format "%.2f" [expr {double($elapsedMS)/1000}]]
}
bind . <Control-c> {destroy .}
bind . <Control-q> {destroy .}
focus .
+
+# Local Variables:
+# mode: tcl
+# End: