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

EDIT: Jul 4, 2013

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.