Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Perl Tk Asynchronous Progress Updates

by Khen1950fx (Canon)
on Jul 02, 2013 at 02:34 UTC ( #1041946=note: print w/ replies, xml ) Need Help??


in reply to Perl Tk Asynchronous Progress Updates

Maybe this will save you time:

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ProgressBar; my $mw = MainWindow->new(-title => 'ProgressBar example'); my $percent_done = ''; my $progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [0, 'red', 50, 'white' , 80, 'blue'], -variable => \$percent_done )->pack(-fill => 'x'); $mw->Button(-text => 'Go!', -command=> sub { foreach (my $i = 0; $i < 1000; ++$i) { $percent_done = $i/10; print "$i\n"; $mw->update; } })->pack(-side => 'bottom'); MainLoop;
Google for some more examples. Good luck.


Comment on Re: Perl Tk Asynchronous Progress Updates
Download Code
Re^2: Perl Tk Asynchronous Progress Updates
by Anonymous Monk on Jul 02, 2013 at 03:51 UTC
    Thanks, but my problem is not in using the progressbar widget (I can do this successfully), but in making the callback which updates it execute asynchronously. My update function is more complicated than a simple for loop (as in your example) and takes a while to run (so I need the application to be responsive in the mean time).
      The example that I gave you can be used with threads ideally, eg., using the button in each of your threads. It shouldn't detract from your application's responsiveness. Yes, you'll need to understand threads:-).

        I see. I was hoping to avoid threads, but I guess I might have to end up using them after all. I suppose this means I will have to share data between them using threads::share in order to update the progress widget part of the main thread.

        thanks for the advice,

        Hermes

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041946]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-09-23 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls