My objective is to turn my "frame" into a text widget as soon as the button is pressed so that in the text widget I can display the output of the command line command (another process).

"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); }

In reply to Re: how to display output of a process in text widget in real time by Marshall
in thread how to display output of a process in text widget in real time by perlnu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.