tags:

views:

30

answers:

1

Hi, I want to add a new widget to my script that will open a new window with text and will close automatically after 1sec.

how can I do it ?

+1  A: 

I think what you want is Tk::after.

#!/usr/bin/perl

use strict;
use warnings;

use Tk;

my $mw    = MainWindow->new;
my $spawn = $mw->Button(
    -text    => 'spawn',
    -command => sub {
        my $subwindow = MainWindow->new;
        my $label     = $subwindow->Label(-text => "spawned");
        $label->pack;
        $subwindow->after(1_000, sub { $subwindow->destroy; });
    }
);
$spawn->pack;
my $exit = $mw->Button(
    -text    => 'exit',
    -command => sub { print "exiting...\n"; exit }
);
$exit->pack;

MainLoop;
Chas. Owens