Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl Tk Asynchronous Progress Updates

by Khen1950fx (Canon)
on Jul 02, 2013 at 02:34 UTC ( [id://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,

        Hermes

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found