in reply to how to display output of a process in text widget in real time
"turning a frame into a text widget" makes no sense. A frame is something that you would put a text widget into. You might want to make a new text widget appear inside of a frame or not. I doubt that you would want to destroy that frame.
Below is a simple Tk application. Make and copy the testing123.pl code into its own file. Run main program. Some kind of event like clicking a button is needed to start the whole process. The testing123.pl program randomly puts a little delay so that you can see that the lines are being displayed in realtime. The key to that is that a screen update method is called to "refresh" the screen after every line is added.
Update: I noticed that if you press GoButton again, it adds yet another text widget underneath the first one. I guess that is a "feature" of this demo!
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; my $main_frame = $mw->Frame()->pack(-side=>'top',-fill=>'x'); my $go_button = $main_frame->Button(-text=>'Go Button', -command => \&do_command)->pack(); MainLoop; sub do_command { # create and display text widget my $tw = $main_frame->Text()->pack(); open (COPY_PROJ, '-|', 'perl testing123.pl') or die "unable to star +t $!"; my $first_line = "Copying project...please wait"; $tw->insert( 'end', $first_line ); my $copy_proj_line; while (defined ($copy_proj_line =<COPY_PROJ>) ) { $tw->insert( 'end', $copy_proj_line ); $tw->update(); ### this is the key to see values as they come } } __END__ file: testing123.pl: #!/usr/bin/perl -w use strict; $|=1; #no buffering on stdout for (1..10) { print "line number $_\n"; sleep 1 if (rand() > 0.5); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to display output of a process in text widget in real time
by perlnu (Initiate) on Jul 12, 2011 at 17:56 UTC | |
by Marshall (Canon) on Jul 12, 2011 at 18:18 UTC | |
by perlnu (Initiate) on Jul 12, 2011 at 22:20 UTC | |
by Marshall (Canon) on Jul 14, 2011 at 20:00 UTC |