开发者

Create new perl/tk window that will automatically close after 1sec

开发者 https://www.devze.com 2023-01-14 18:19 出处:网络
I want to add a new widget to my script that will open a new window with text and will close a开发者_高级运维utomatically after 1sec.

I want to add a new widget to my script that will open a new window with text and will close a开发者_高级运维utomatically after 1sec.

how can I do it ?


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

精彩评论

暂无评论...
验证码 换一张
取 消