moked has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I'm using the next popup window:
sub compok{ my $Cok = MainWindow->new(title=>"Copy succeeded"); my $Cok1 = $Cok -> Frame; # $widget -> configure(-size=>14,-weoght=>'bold'); # $FFont -> weight(bold); $Cok1->Label(-text=>"\n\nWONDERFULL\n\nGREAT\n\nINCREDIBLE\n\nMAGN +IFICENT\n\nYOUR COMPILATION PASSED\n\nAND I'VE JUST FINISHEAD COPYING + YOUR FILES\nINTO $Dest_Dir!\n\n\n", -font => 14, # -weight => 'bold', -height => '1.5', -background => 'lightblue')->pack(-side=>"top",-fill=>"both",- +anchor=>"w",qw/-ipadx 70 -ipady 120/); $Cok1->Button( -text => 'OK', -background => 'lightgreen', -command =>[$Cok => 'destroy'])->pack(qw/-ipadx 4 -pady 2/); $Cok1 -> pack; MainLoop; }
I want to add an option that will close the window
after 30 seconds if nothing happens

Any suggestions??

Thanks ahead,
Moked

Replies are listed 'Best First'.
Re: timed window
by zentara (Cardinal) on Feb 26, 2006 at 12:54 UTC
    Instead of using alarm, you should use Tk's method of creating timers. ( P.S. I also changed your destroy syntax to be more understandable)
    #!/usr/bin/perl use warnings; use strict; use Tk; compok(); sub compok{ my $Cok = MainWindow->new(title=>"Copy succeeded"); my $Cok1 = $Cok->Frame; $Cok1->Label(-text=>"\n\nWONDERFULL\n\n") ->pack(-side=>"top",-fill=>"both", -anchor=>"w", qw/-ipadx 70 -ipady 120/); $Cok1->Button( -text => 'OK', -background => 'lightgreen', -command => sub{ $Cok->destroy } ) ->pack(qw/-ipadx 4 -pady 2/); $Cok1->pack; #5000 millisec -- 5 seconds my $timer = $Cok->after(5000, sub{ $Cok->destroy }); MainLoop; }

    I'm not really a human, but I play one on earth. flash japh
Re: timed window
by mickeyn (Priest) on Feb 26, 2006 at 12:05 UTC
    You can use:

    $SIG{ALRM} = { ... code to execute on time-out ... }; alarm 30; # will wait 30 secs before calling your time-out code ... regular code ... alarm 0; # set this if ok to neutralize the alarm

    this is only good if the alarms are not nested.

    Enjoy,
    Mickey