Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl Tk--Delay

by FM (Acolyte)
on Oct 20, 2005 at 22:45 UTC ( [id://501833]=perlquestion: print w/replies, xml ) Need Help??

FM has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I am troubled by the behavior of my code. I was hoping to show my user what the program that I transparently call is doing as it is doing it, but instead, Perl calls the program even before the textarea is drawn. I even made a separate method to see if that would make a difference, which it does not.
I would be most greatful if anyone could point me in the right direction.
Below is only the snipped where it is not acting right.
if($answerbatch eq 'CONTINUE'){ $progressta->place(-x=>0, -y=>0); cont(); }else{ clearthird(); }#else sub cont{ my $i=0; foreach (@arrayfilename){ $_ .= ".log\""; system ("robocopy $gGui{original_source}$arraydirectory[$i]\" $gGui{ +original_dest}$_"); $progressta->insert('end lineend', "Robocopy is now processing $_,\n +"); $i++; }#foreach first(); }#cont
Thanks in advance for your time
FM

Replies are listed 'Best First'.
Re: Perl Tk--Delay
by GrandFather (Saint) on Oct 20, 2005 at 23:23 UTC

    Is something like this what you are looking for:

    use warnings; use strict; use Tk; my $main = MainWindow->new (); my $progressta = $main->Label ()->pack (); for (1..10) { $progressta->configure (-text => "Robocopy is now processing $_"); $main->update (); sleep (2); } MainLoop ();

    Perl is Huffman encoded by design.
      Thanks
Re: Perl Tk--Delay
by graff (Chancellor) on Oct 20, 2005 at 23:48 UTC
    Based on how you described the problem, I'm not sure you've shown us enough code to identify the cause. Either that, or else I don't understand what your problem is.

    Is it the case that your "cont()" sub is supposed to be called in response to some user input event (a button click or such)? If so, then the "if($answerbactch...)" condition is supposed to be in a callback routine, to be triggered by the user's input (e.g. as the "-command" parameter for some button widget).

    Maybe instead of passing a reference to the sub for the "-command" parameter, you're actually executing the sub when declaring the widget? I really am just guessing here about parts of your code that you have not shown us, but a lot of Tk users tend to get tripped up on this sort of problem.

Re: Perl Tk--Delay
by Courage (Parson) on Oct 21, 2005 at 09:52 UTC
    You need $widget->update call to redraw so user will see your "program" (as you said this:)

    Also, "afterIdle" and "after" could be used in your code as well.

      Thanks. It sure makes a difference...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://501833]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found