in reply to Stopwatch GUI sleep

Here's one implementation of Tk::after using a status var to indicate if the counter should be incremented

#!/usr/bin/perl use Tk; use strict; use warnings; my $count = 0; my $count_on = 0; my $window = MainWindow->new; $window->title("My Example"); $window->Label(-textvariable => \$count )->pack; $window->Button( -text => "Start", -command => sub {$count_on = 1}, )->pack; $window->Button( -text => "Stop", -command => sub {$count_on = 0}, )->pack; my $timer = Tk::After->new($window, 1000, 'repeat', sub { $count++ if +$count_on }); MainLoop;

Replies are listed 'Best First'.
Re^2: Stopwatch GUI sleep
by welle (Beadle) on Apr 08, 2011 at 14:58 UTC

    Hello Wind, it just works perfectly!