Thanks again! I'll take a look at that. Meanwhile, further work with your original suggestion has produced something like this (not complete):

my $Q = new Thread::Queue; my $mw = MainWindow->new(); my $run_button = $mw -> Button(-text => "Run Programs", -command=> sub { threads->create(\&runprogs, $Q)->detach(); &view_out; + }); sub runprogs { # run the main script my $pipe = IO::Pipe->new(); $pipe->reader("$script $args 2>&1"); $Q->enqueue( $_ ) while <$pipe>; $Q->enqueue ( undef ); sleep; } sub view_out { # create display window my $top = $mw-> Toplevel(); my $label = $top -> Label(-text=>"Script output",-relief=>"groove")- +>pack(); my $ro = $top->Scrolled('ROText', -width => 60, -height=>20, -scroll +bars=>"e")->pack(); # continuously display output while (my $thingy = $Q->dequeue_nb()) { last unless (defined $thingy); $ro->insert("end", "$thingy"); $ro->update(); sleep 1; } # add close button my $close = $top -> Button(-text=>"Close window", -command => sub { +destroy $top; })->pack(); }

This works, but if I omit the "sleep" from &runprogs, or have a return in there then all manner of horrible things happen. Presumably this is because I have misunderstood how this all works and cocked up the queueing somehow.


In reply to Re^4: Tk + threads by knirirr
in thread Tk + threads by knirirr

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.