in reply to Re: How to implement a timer in perl?
in thread How to implement a timer in perl?
#dialog moduleuse strict; use warnings; use lib qw(.); use Data::Dumper; use TimeOutDialog; my $x; TimeOutDialog::ask(\$x); if ( defined ($x) ) { print "*$x*"; } else { print "timeout\n"; }
package TimeOutDialog; use Tk; sub ask { my $mw = MainWindow->new(); my $target = shift; my $label = $mw->Label ( -text => "Please anwer my question:" )-> +pack; my $text = $mw->Entry->pack; my $button = $mw->Button ( -text => 'confirm', -command => sub { $$target = $text->get(); $mw->destroy; }, )->pack; my $id = $mw->after ( 5000, sub { $$target = undef; $mw->destroy; } ); MainLoop; } 1;
|
|---|