[英]Create new perl/tk window that will automatically close after 1sec
I want to add a new widget to my script that will open a new window with text and will close automatically after 1sec. 我想在脚本中添加一个新的小部件,该小部件将打开一个包含文本的新窗口,并在1秒后自动关闭。
how can I do it ? 我该怎么做 ?
I think what you want is Tk::after
. 我认为您想要的是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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.