in reply to Re: Perl Tk Asynchronous Progress Updates
in thread Perl Tk Asynchronous Progress Updates

Thanks for the example, but the idea was that I would prompt the user for input (using an entry widget) and then initiate the download. The updates are supposed to be asynchronous so a button doesn't need to pushed to see the progress. The idea is that once a download has been initiated the update function should run in the background so as not to hang up the application (the download link is retrieved via an entry widget). Your sample code has the same issue that mine did, namely that the download routine runs before the gui is even displayed. Do you have the same issue when you run your code? Perhaps something is wrong with my version of Tk ( though I've had this problem on two different machines running different linux distributions, so that's unlikely).
  • Comment on Re^2: Perl Tk Asynchronous Progress Updates

Replies are listed 'Best First'.
Re^3: Perl Tk Asynchronous Progress Updates
by Sandy (Curate) on Jul 02, 2013 at 17:23 UTC
    I think that you may be missing the focus of kcott's post. It is the repeat function.

    Obviously, you start the progress bar when you are ready.

    Example

    use Tk; use Tk::ProgressBar; my $mw = MainWindow->new(); my $per = 0; $mw->ProgressBar(-variable=>\$per)->pack; $mw->Button(-text=>"Go",-command=>\&GoForIt)->pack; MainLoop; ######### This is the important bit ########### sub GoForIt { $mw->repeat(25=>sub{$per+=10;return if $per>100;;$mw->update;sleep +(1)}) }
Re^3: Perl Tk Asynchronous Progress Updates
by kcott (Archbishop) on Jul 02, 2013 at 16:23 UTC

    What you're describing doesn't make any sense to me: I can't see how the (simulated) downloads in my code could have possibly run before the GUI is displayed.

    When you ran my code, did you really see all progress bars showing completion? I see them starting at the far left and moving towards the right.

    Did you change my code before running it? I can't think of any reason why the code I posted would not run, as is, under Linux; however, if you did change it, please show the actual code you are running.

    -- Ken

      I ran the code unmodified (Well, I added a "MainLoop" to the end since it was missing). The application paused before starting then displayed the progress bars full. I think it may be an issue with my Tk package, I am going to try it on another machine.

      Thanks
      Hermes.
        "I ran the code unmodified (Well, I added a "MainLoop" to the end since it was missing)."

        The last line of the script I posted is:

        MainLoop;

        It's not missing. It never was missing.

        I've even checked the "[download]" link (http://www.perlmonks.org/?abspart=1;displaytype=displaycode;node_id=1041950;part=2). No problems encountered: it's the last line there too.

        This suggests that your download of the code I posted is corrupt. As a first step in troubleshooting this problem, try downloading it again and then see if the new copy works.

        There is nothing in the code I posted that was not available in the earliest version of Tk on CPAN, which is dated 28 Jul 1999 (see Tk800.015). Furthermore, that version of Tk required Perl 5.004_04 (see Tk800.015 source) which is dated 1997-Oct-15 (see perlhist).

        While you may choose to upgrade Perl or Tk to newer versions than you currently have, it would seem extremely unlikely that you would need to in order to get this script to work. For what it's worth, I'm using the latest versions of both (Perl 5.18.0 and Tk 804.031).

        "The application paused before starting then displayed the progress bars full."

        That just shouldn't happen. If, after following the suggestions above, you still see this behaviour, try reinstalling Tk.

        "I think it may be an issue with my Tk package, I am going to try it on another machine."

        If you think the problem lies with Tk, then reinstall Tk and try again. If you think the problem is your "machine", check CPAN Testers Reports for Tk before trying on another (arbitrary) "machine".

        -- Ken

Re^3: Perl Tk Asynchronous Progress Updates
by Anonymous Monk on Jul 02, 2013 at 15:37 UTC