如何在 Perl Tk 中显示来自外部命令的文本?

发布于 2024-09-28 17:57:06 字数 262 浏览 1 评论 0原文

我必须在 Tk GUI 中显示一些打印语句(在运行 Perl 脚本时得到)。我尝试用图文并茂的方式展示一个例子,例如:

Initializing the parser ...

Running the parser ...

Enabling the codec ...

Connected to the socket ...

Sending ipv4 traffic into the code ...

事情是这样的。我不知道该怎么做。

I have to display some print statements (which I get while running a Perl script) in the Tk GUI. I tried to show an example in pictorial format, for example:

Initializing the parser ...

Running the parser ...

Enabling the codec ...

Connected to the socket ...

Sending ipv4 traffic into the code ...

It goes on like this. I don't know how to do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-10-05 17:57:06

您可以通过 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' );

You could run your perl script through 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;

In general, you need to do some sort of IPC to run a batch and update a Tk GUI. Because IO handles can create events in Tk. Tk::ExecuteCommand kind of hides the complexity of the IPC.

Otherwise, you can design the IPC scheme of your own. Probably (roughly put) pipe, fork, and setup pipe events as a IO event, and the crucial commands to make a read-only log are:

$text->configure( -state => 'normal' );
$text->insert( end => $text_I_just_read_from_the_pipe );
$text->configure( -state => 'disabled' );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文