Hey guys, I am trying to write a graphical application using Tk that allows the user to download multiple files and displays progress updates for each file (i.e a simple download manager). Presently, I am trying to set up a simple progress bar that is periodically updated. I have bound the update function to a button like so
my $pbar=$mw->ProgressBar(-variable=>\$percent); $mw->Button(-text=>'Begin',-command=>[\&updateprog,\$percent])->pack; $pbar->pack;
Unfortunately this means that the main event loop waits for the update function to complete before handing control back to the user (so the button is depressed for a long period of time.). I want to make the progress update asynchronous, but don't know where to start. I suspect the answer involves threads, but I have relatively limited experience using them. On the other hand I feel that using separate threads might be overkill and that there is probably a better way to handle this (though I have yet to find it). If one of you kind souls could point me in the right direction, I would greatly appreciate it.
Thanks,
Hermes
Thanks for all the help guys. There were two problems as it turns out. The first is that my Tk install was broken, I retested some code on another machine and it worked more or less as expected. The second is that I was using sleep in my tests, which as I've learned doesn't play nicely with Tk's event handling. After using repeat as suggested things seem to be working smoothly now. The only problem is that I've realized that I don't have control of the callback LWP makes, so I can't run it using Tk repeat. It looks like I will have to resort to threads.Unless anyone has a better idea.
Thanks again,
Hermes
In reply to Perl Tk Asynchronous Progress Updates by hermes1908
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |