tags:

views:

29

answers:

1

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.

+4  A: 

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' );
Axeman
thanks buddy..i modified this code and it satisfies my necessity.
Senthil kumar