我必须在 Tk GUI 中显示一些打印语句(我在运行 Perl 脚本时得到的)。我试图以图片格式展示一个示例,例如:
Initializing the parser ...
Running the parser ...
Enabling the codec ...
Connected to the socket ...
Sending ipv4 traffic into the code ...
就这样继续下去。我不知道该怎么做。
你可以通过运行你的 perl 脚本Tk::ExecuteCommand
use Tk;
use Tk::ExecuteCommand;
$ec = tkinit()->ExecuteCommand(
-command => '',
-entryWidth => 50,
-height => 10,
-label => '',
-text => 'Execute',
)->pack;
$ec->configure(-command => 'perl ./my_other_perl_script.pl');
$ec->execute_command;
$ec->update;
通常,您需要执行某种 IPC 来运行批处理并更新 Tk GUI。因为 IO 句柄可以在 Tk 中创建事件。Tk::ExecuteCommand
有点隐藏了 IPC 的复杂性。
否则,您可以设计自己的IPC方案。可能(粗略地说)管道、分叉和设置管道事件作为 IO 事件,制作只读日志的关键命令是:
$text->configure( -state => 'normal' );
$text->insert( end => $text_I_just_read_from_the_pipe );
$text->configure( -state => 'disabled' );