#!/usr/local/bin/perl -w
#####################################
# Contador para el fin del mundo
#
#######################
use Date::Calc qw(Delta_DHMS);
use Time::localtime;
use strict;
use Tk;
my @W_End = (2012, 12, 21, 00, 00, 01); # 21 Dec 2012, 0:00:01
my $str = "...";
my $mw = new MainWindow;
$mw->title("Fin del mundo");
$mw->Label(-text => "Faltan para el fin del mundo")->pack;
my $entry = $mw->Entry(
-textvariable => \$str,
-width => 17,
-font => "{Comic Sans MS} 12",
-relief => 'raised',
-highlightthickness => 0,
-state => 'disable',
)->pack();
$mw->Button(-text => 'Quit',
-justify => 'center',
-command => sub{exit} )->pack;
$mw->repeat(1000 => \&downcounter);
MainLoop;
sub downcounter {
# Calculando fecha actual
my @Today = (localtime->year()+ 1900, localtime->mon()+ 1, localtime->mday(), localtime->hour(), localtime->min(), localtime->sec());
my @diff = Delta_DHMS(@Today, @W_End);
if ( $diff[1] <10 ){
$diff[1]="0$diff[1]";
}
if ( $diff[2] <10 ){
$diff[2]="0$diff[2]";
}
if ( $diff[3] <10 ){
$diff[3]="0$diff[3]";
}
$str = "$diff[0] dias, $diff[1]:$diff[2]:$diff[3] ";
}
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario