Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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.

Replies are listed 'Best First'.
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,


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041946]
[Discipulus]: ah ah I have two post in weekkly best! free coffe for all!
[Corion]: Gratulations! :-D

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-02-22 09:19 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (289 votes). Check out past polls.