我的任务需要通过gui在perl中持续执行。
设置包括文本字段,按钮和文本区域。按下该按钮时,系统命令将使用文本字段中的值重复运行,并在文本区域中显示输出。
例如,请考虑以下代码: 使用Tk;
# Main Window
my $mw = new MainWindow;
#GUI Building Area
my $frm_name = $mw -> Frame();
my $lab = $frm_name -> Label(-text=>"Command");
my $ent = $frm_name -> Entry();
#Button and command
my $ent = $mw -> Entry() -> pack();
my $but = $mw -> Button(-text=>"Run Command", -command =>\&push_button) -> pack();
#Text Area
my $textarea = $mw -> Frame();
my $txt = $textarea -> Text(-width=>40, -height=>10) -> pack();
#Geometry Management
$lab -> grid(-row=>1,-column=>1);
$ent -> grid(-row=>2,-column=>1);
$frm_name -> grid(-row=>1,-column=>1,-rowspan=>2);
$but -> grid(-row=>1,-column=>1,-columnspan=>1);
$txt -> grid(-row=>1,-column=>1);
$textarea -> grid(-row=>5,-column=>1,-columnspan=>2);
MainLoop;
## Functions
#This function will be executed when the button is pushed
sub push_button {
my $name = $ent -> get();
@out = qx($name);
$txt -> insert('end', @out);
}
现在,我想要做的是使push_button()子每30秒运行一次,并在文本字段中输出输出。
我查看了repeat()函数,但无法正常运行。任何帮助将不胜感激。感谢。
答案 0 :(得分:5)