Those two updates obviously will not work the way you expected. They only get accessed after the downloading is completed. During the downloading, your GUI will just sort of "hang".

I have some script, sort of still "work in progress", but it helps you to attack this problem. What I did was that, I wrote the download part myself, instead of using any module so that I know the progress, and can update the progressbar every time after a portion of the downloading is done: (I am still working on it, so lots of stuffs are hardcoded, but the idea is certainly there. Take a look.)

use Tk; use Tk::Progressbar; use IO::Socket::INET; use IO::Select; use strict; use warnings; my $mw = MainWindow->new(); $mw->Button(-text => "Download", -command => \&download)->pack(); MainLoop; sub download { my @documents; for (1..20) { push @documents, "song$_.Wma"; } my $connections; my $selector = IO::Select->new(); while (1) { if (my @readers = $selector->can_read(5)) { for my $reader (@readers) { my $line; if (my $length = sysread($reader, $line, 2048)) { syswrite($connections->{$reader}->{"file"}, $line) +; $connections->{$reader}->{"received"} += $length; $connections->{$reader}->{"progress"}->value($conn +ections->{$reader}->{"received"} / $connections->{$reader}->{"length" +} * 100); $mw->update(); } else { close $connections->{$reader}->{"file"}; delete $connections->{$reader}; $selector->remove($reader); close $reader; } } } else { if (my $document = pop @documents) { if (my $connection = IO::Socket::INET->new(Proto => "t +cp", PeerAddr => "music.eting.cn", PeerPort => 80)) { binmode($connection); $selector->add($connection); print $connection "GET http://blah.com/$document H +TTP/1.1\r\nHost: 0.0.0.0\r\n\r\n"; my $line; my $offset = 0; while (1) { my $len = sysread($connection, $line, 2048, $o +ffset); print $line; if ($line =~ m/\r\n\r\n/) { last; } else { $offset += $len; } } $line =~ m/Content-Length: (\d*)/; print "$1\n"; $connections->{$connection}->{"length"} = $1; my $file; open $file, ">", $document; binmode($file); $line =~ m/.*?\r\n\r\n(.*)/s; syswrite($file, $1); $connections->{$connection}->{"received"} = length +($1); $connections->{$connection}->{"file"} = $file; $connections->{$connection}->{"document"} = $docum +ent; my $frame = $mw->Frame()->pack(); $frame->Label(-text => $document)->pack(); $connections->{$connection}->{"progress"} = $frame +->ProgressBar( -width => 20, -length => 200, -anchor => 'w', -from => 0, -to => 100, -blocks => 1, -colors => [0, 'green'])->pack(); $mw->update(); } } else { unshift @documents, $document; } } } }

In reply to Re: LWP::Simple causing Tk error by pg
in thread LWP::Simple causing Tk error by wook

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.