0

Tk GUI でいくつかの print ステートメント (Perl スクリプトの実行中に取得) を表示する必要があります。例を図形式で表示しようとしました。たとえば、次のようになります。

Initializing the parser ...

Running the parser ...

Enabling the codec ...

Connected to the socket ...

Sending ipv4 traffic into the code ...

このように続きます。やり方がわかりません。

4

1 に答える 1

4

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;

一般に、バッチを実行して Tk GUI を更新するには、ある種の IPC を実行する必要があります。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' );
于 2010-10-26T16:49:55.277 に答える