use 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;