G'day hermes1908,

Welcome to the monastery.

I don't think your users would be too happy having to manually update the download progress by pressing a button. This is really something you'd want to display dynamically. Consider how it's done in a simple text-based scenario (e.g. wget) or in a graphical context such as your browser: you don't need to hit keys or press buttons to see what progress has been made.

When designing a GUI, think about how it's been done previously and how your users would expect it to work. Unless you are intending to present something that is fundamentally different from the norm, stick with the status quo.

Here's a working (albeit barebones) script that simulates 3 files being downloaded simultaneously and shows progress dynamically.

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::ProgressBar; my @file_data = ( { name => 'File1', size => 1000 }, { name => 'File2', size => 5000 }, { name => 'File3', size => 2500 }, ); my $mw = MainWindow->new(); $mw->geometry('400x200+50+50'); my $control_F = $mw->Frame()->pack(-side => 'bottom'); $control_F->Button(-text => 'Exit', -command => sub { exit } )->pack(-padx => 5, -pady => 5); my $progress_F = $mw->Frame( )->pack(-padx => 10, -pady => 10, -fill => 'both', -expand => 1); for my $file_datum (@file_data) { my $download_amount = 0; my $download_percent; my $download_F = $progress_F->Frame( )->pack(-padx => 10, -pady => 10, -side => 'top', -fill => 'x' +); $download_F->Label(-text => $file_datum->{name} )->pack(-padx => 5, -side => 'left'); $download_F->ProgressBar(-variable => \$download_percent )->pack(-padx => 5, -side => 'left', -fill => 'x', -expand => +1); $download_F->repeat(25 => sub { $download_amount += int rand 10; if ($download_amount > $file_datum->{size}) { $download_amount = $file_datum->{size}; } $download_percent = $download_amount / $file_datum->{size} * 1 +00; }); } MainLoop;

-- Ken


In reply to Re: Perl Tk Asynchronous Progress Updates by kcott
in thread 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.