0

我想在我的脚本中添加一个新的小部件,它将打开一个带有文本的新窗口,并在 1 秒后自动关闭。

我该怎么做 ?

4

1 回答 1

1

我想你想要的是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;
于 2010-08-31T12:13:45.533 回答