#!/usr/bin/perl use strict; use Time::HiRes qw(ualarm); use Tk; BEGIN {*Tk::Clock::time = sub { time * -1 } } use Tk::Clock; my $wm = MainWindow->new; my $ck = $wm->Clock->pack(-side => 'top'); my $b = $wm->Button(-text => 'Start Process', -command => \&mainprocess)->pack; $ck->config(dateFormat => "dd-mm-yyy"); MainLoop; # # simulate a long running, CPU-intensive task # sub mainprocess { local $SIG{ALRM} = sub { DoOneEvent(Tk::Event::DONT_WAIT); ualarm(1000); } ualarm(1000); # task body begin my $c; $b->configure(-text => 'running...'); while (1) { $c++; print $c,"\n" unless $c % 1000; last if $c == 10000000; } $b->configure(-text => 'Start Process'); # task body end ualarm(0); }