Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl TK Delayed after click OK to execute

Status
Not open for further replies.

clueo8

Programmer
Jun 13, 2005
47
US
I have a bunch of prepare and execute statements that will run after a user clicks OK on a Perk TK dialog box. Most of the time it will freeze on the mouse release and do its work behind the scene, then when its done, my script output window displays.

I would like the script output to display immediately on the mouse click release. Is this possible?
 
Of course.
Instead of running straight into your processing code, open the output window after creating it containing a label with a message like "Processing, please wait ..." in it.
When your code then completes, it can update that label, or indeed the whole window with your results.


Trojan.
 
Thank you for your quick response!

I have the continue YES NO prompt... When yes is pressed, it goes right to a sub routine that creates a window in the first line, with a label saying "Please Wait..." and buttons and the whole works... also a larger script output window that has a scroll bar is on the new window...

I don't know if you suggestion is any different...
 
I guess your problem might be that you are not calling MainLoop again (for obvious reasons) and therefore your screen is not updated.
Hmmm.
I haven't done Tk for ages so I'll have to go check up on this.
Maybe someone else can answer "off the cuff" so to speak.
If not, I shall try to get back to you later.



Trojan.
 
I'm wondering if you might do well to use threads in this program.
You could start the thread when the user clicks the OK button and the code would immediately return (having started the processing thread) allowing the screen update to happen.

Food for thought, maybe.



Trojan.
 
I'm not too formiliar with threads except for the thread I'm currently posting!
 
LOL

Don't worry, I'm still thinking about this one.
I seem to remember there is a way to "refresh" the window during processing so you can call something on every iteration of your processing loop to ensure that the window is updated instantly and correctly.

I'll get back to you again when I have more specific info.



Trojan.
 
I do have something similar to that, sort of like a flush which displays these things on the script window.

I have:
Code:
$script_output->idletasks;
$script_output -> see ('end');
at the end of every time I appent text to the script window.
 
I think the answer you wanted was $mw->update.
Assuming that your "mainwindow" is $mw, call update on it at the start of your slow function and at regular intervals during it to keep some fluidity.

I wrote a scratchy test script that might give you some ideas:
Code:
#!/usr/bin/perl -w
use strict;
use diagnostics;
use Tk;

my $mw = MainWindow->new;
$mw->Label(-text => 'Hello, world!')->pack;
$mw->Button(
   -text    => 'Process',
   -command => sub { process($mw); },
)->pack;
MainLoop;

sub process
{
    my $mw = shift;

    print "About to refresh\n";
    $mw->update();
    print "Refreshed\n";
    sleep 5;
    $mw->Label(-text => 'Finished processing!')->pack;
}
Apologies if the code is a little scratchy and rough. I haven't done Tk for ages.


Hope this helps though.


Trojan.
 
You are the man!

Update worked perfectly!
 
Thanks again Trojan Man!

You have saved yet another programmer!
 
I guess I missed the bus on this one, but glad you solved the problem.

On a side note, do not use threads with TK. It does not work.


Michael Libeson
 
Yeah, as soon as I suggested it I decided that threads was a bad idea. But hey, I got there in the end. :-D


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top