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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |