knirirr has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk + threads
by BrowserUk (Patriarch) on Jan 10, 2006 at 15:13 UTC | |
by knirirr (Scribe) on Jan 10, 2006 at 16:26 UTC | |
by BrowserUk (Patriarch) on Jan 10, 2006 at 16:59 UTC | |
by knirirr (Scribe) on Jan 10, 2006 at 17:18 UTC | |
by BrowserUk (Patriarch) on Jan 10, 2006 at 18:24 UTC | |
| |
|
Re: Tk + threads
by zentara (Cardinal) on Jan 10, 2006 at 17:07 UTC | |
|
Re: Tk + threads
by markwx (Acolyte) on Jan 10, 2006 at 15:00 UTC | |
by knirirr (Scribe) on Jan 10, 2006 at 16:42 UTC |