Hello fellow monks,

I love TK. The ease with which a gui can be built with Perl and TK is incredible.... but I digress from my problem.

I know there must be a simple solution, but as usual I am probably just overlooking the forest for the trees. Several of the scripts that I have created for use at work have to parse through many files and/or transfer files to and from remote workstations. This can take from 1 minute to 30 minutes depending on the script.

The precise problem that I am having is that I want the subruotine to be able to update the mainwindow (or toplevel window as appropriate) as to what it is doing. I have tried putting a label into the main window and having the subroutine configure->Label("This is what I am doing now"); but until the subroutine completes, none of these updates are actually executed by the window.
Example:
#!/usr/bin/perl -w use strict; use Tk; use LWP::Simple; my($label); my $w=new MainWindow; my $root='http://www.billwfriend.com/outdoors/hiking/ricketts_glen'; my @pics=('DSC00005.JPG','DSC00006.JPG','DSC00007.JPG','DSC00008.JPG', +'DSC00009.JPG','DSC00011.JPG','DSC00012.JPG','DSC00014.JPG','DSC00072 +.JPG'); $w->title("TK Sample"); my $test=$w->Button(-text=> 'Test', -command => sub{&test})->pack(); my $quit=$w->Button(-text=> 'Quit', -command => sub{exit})->pack(); &MainLoop; sub test { $label=$w->Label(-text=>"Starting to get files.")->pack(); foreach my $file (@pics) { &get_url($file); } } sub get_url { my $file=shift; $label->configure(-text=>"Starting to get $file"); my $test=get("$root/$file"); open(TEST, ">$file") || die"can't open $file\n"; binmode TEST; # for MSDOS derivations. print TEST $test; close TEST; $label->configure(-text=>"Got $file."); }
I know this code example could be made much cleaner, I just threw this together to illustrate my problem, the actual scripts I am speaking of are much larger.

In the above example, the Got $file does not get put into the MainWindow until the last file in @pics is processed.

How do I get the Perl/TK to execute the configure command immediately instead of waiting for the subroutine to complete? Or is there a better method altogether?

Thanks in advance for all your help.

-Kevin
my $a='62696c6c77667269656e6440676d61696c2e636f6d'; while ($a=~m/(^.{2})/s) {print unpack('A',pack('H*',"$1"));$a=~s/^.{2}//s;}

In reply to TK subroutine status by K_M_McMahon

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.