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:
Initializ开发者_C百科ing 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.
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' );
精彩评论