Despite reading previous examples of questions involving Tk and threads, I still can't work out the following. I have a script that runs various other programs and collates the results. It requires a large configuration file, and since users don't like to edit this I've written a Tk front end that allows them to set up the configuration. It then writes out a config file and runs original script. The users need to see the output of the script, so I have the front end run something like this:

sub runprogs { # run the main script my $pipe = IO::Pipe->new(); $pipe->reader("$original_script 2>&1"); # create display window my $top = $mw-> Toplevel(); my $label = $top -> Label(-text=>"STDOUT from script",-relief=>"groo +ve")->pack(); my $ro = $top->Scrolled('ROText', -width => 60, -height=>20, -scrollb +ars=>"e")->pack(); # continuously display output while (<$pipe>) { $ro->insert("end", "$_"); $ro->update(); sleep 1; } # add close button my $close = $top -> Button(-text=>"Close window", -command=>sub { destroy $top; })->pack(); }

The effect of this is that both the main window $mw and $top won't update whilst the while loop is running. The program can take some time to run, so users may minimise the windows and find them blank upon viewing them again before this loop has finished.

I cannot, of course, simply run the code above as a thread and detach it, as it makes reference to an existing Tk object. Can anyone suggest a better way to get around this?


In reply to 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.