Hey Guys/Gals,
The following program displays the amount of Days Hours Minutes and Seconds till Friday 5pm. THen there's a update button which you hit and it updates the amount of time. I want to get rid of the Update button and have the Label widget update by itself, so you actually see the seconds and stuff counting down.. Can someone please help !#%? It's driving me crazy that i cant figure how to do it. Thanks!
-------------------------------------------------------------------
#!/usr/local/bin/perl
use Tk;
use POSIX;
my $mw = MainWindow->new();
$mw->geometry("+0-0");
$mw->title('Countdown to Friday 5pm');
sub count {
$| = 1;
while(1) {
my $now = time();
my $weekend = $now;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime( $now );
$weekend -= ( $sec );
$weekend -= ( $min * 60 );
if ( $hour >= 17 ) {
$weekend -= ( $hour - 17 ) * 60 * 60;
} else {
$weekend += ( 17 - $hour ) * 60 * 60;
}
if ( $wday >= 5 ) {
$weekend -= ( $wday - 5 ) * 60 * 60 * 24;
} else {
$weekend += ( 5 - $wday ) * 60 * 60 * 24;
}
my $difference = abs( $weekend - $now );
my $wait_days = floor( $difference / ( 60 * 60 * 24 ) );
$difference -= $wait_days * 60 * 60 * 24;
my $wait_hours = floor( $difference / ( 60 * 60 ) );
$difference -= $wait_hours * 60 * 60;
my $wait_minutes = floor( $difference / 60 );
$difference -= $wait_minutes * 60;
my $wait_seconds = $difference;
return sprintf "\r %02dd %02dh %02dm %02ds", $wait_days, $wait_hours, $wait_minutes, $wait_seconds;
};
};
sub update {
&count;
$text = &count;
}
&count;
$text = &count;
$label = $mw->Label(-textvariable => \$text)->pack(-side => 'left');
$CHECK = $mw->Button(-text => 'Update',
-foreground => 'red',
-background => 'black',
-anchor => 'center',
-relief => 'groove',
-command => \&update)->pack();
MainLoop;
The following program displays the amount of Days Hours Minutes and Seconds till Friday 5pm. THen there's a update button which you hit and it updates the amount of time. I want to get rid of the Update button and have the Label widget update by itself, so you actually see the seconds and stuff counting down.. Can someone please help !#%? It's driving me crazy that i cant figure how to do it. Thanks!
-------------------------------------------------------------------
#!/usr/local/bin/perl
use Tk;
use POSIX;
my $mw = MainWindow->new();
$mw->geometry("+0-0");
$mw->title('Countdown to Friday 5pm');
sub count {
$| = 1;
while(1) {
my $now = time();
my $weekend = $now;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime( $now );
$weekend -= ( $sec );
$weekend -= ( $min * 60 );
if ( $hour >= 17 ) {
$weekend -= ( $hour - 17 ) * 60 * 60;
} else {
$weekend += ( 17 - $hour ) * 60 * 60;
}
if ( $wday >= 5 ) {
$weekend -= ( $wday - 5 ) * 60 * 60 * 24;
} else {
$weekend += ( 5 - $wday ) * 60 * 60 * 24;
}
my $difference = abs( $weekend - $now );
my $wait_days = floor( $difference / ( 60 * 60 * 24 ) );
$difference -= $wait_days * 60 * 60 * 24;
my $wait_hours = floor( $difference / ( 60 * 60 ) );
$difference -= $wait_hours * 60 * 60;
my $wait_minutes = floor( $difference / 60 );
$difference -= $wait_minutes * 60;
my $wait_seconds = $difference;
return sprintf "\r %02dd %02dh %02dm %02ds", $wait_days, $wait_hours, $wait_minutes, $wait_seconds;
};
};
sub update {
&count;
$text = &count;
}
&count;
$text = &count;
$label = $mw->Label(-textvariable => \$text)->pack(-side => 'left');
$CHECK = $mw->Button(-text => 'Update',
-foreground => 'red',
-background => 'black',
-anchor => 'center',
-relief => 'groove',
-command => \&update)->pack();
MainLoop;