I have the following code as an example but can't seem to figure out how to use it in my code. In my code I read 5,000+ folders in a file and then parse them and write the results of those files to another directory file by file. I'd like to use the progress bar included here in the subroutine in my script but I don't know where to put the call backs to track time. In this example below they just use a loop and count down. I can do that but it won't be an accurate representation to track with I'm doing.

#!/usr/bin/perl # a nearly trivial script to mount /mnt/camera on # dev/ttyUSB1, create a target dir, and copy pics # from camera to dir. # Note that mount stuff has been excised for brevity. #--------------------------------------------------------------------- $| = 1; use strict; use Tk; use Tk::Pane; use Tk::ProgressBar; my $message = 'Ready'; my $main = MainWindow->new(); $main->configure(-title=>'Camera 2 Disk', -background =>'blue'); $main->geometry('370x200+100+00'); my $label = $main->Label(-text =>"Digital Camera Tool\nCopy Images fro +m Fuji FinePix to Disk", -relief => 'raised', -background =>'#42b4b4') ->pack(-side=>'top', -fill =>'both'); my $button_frame = $main->Frame(-relief=>'raised') ->pack(-side => 'top', -fill => 'x'); my $dump = $button_frame->Button(-text => 'Dump', -command => \&get_files) ->pack(-side =>'left', -anchor => 'w'); my $status_text = 'Ready'; my $status_label = $button_frame->Label( #-textvariable =>\$status_text, -relief => 'raised', -background =>'grey77') ->pack(-side=>'left',-fill=>'both', -expand=>'1'); my $exit = $button_frame->Button(-text => 'Exit', -command => 'exit') ->pack(-side =>'right'); my $status = $main->Scrolled('Pane', -scrollbars => 'se', -relief => ' +flat') ->pack(-side=>'top', -fill=>'both', -expand=>'y'); #$status->Label(textvariable =>\$message, #-relief => 'flat'); #->pack(-side=>'top', -fill =>'both'); my $percent_done; my $position = '0'; my $progress = $main->ProgressBar(-troughcolor => 'grey70', -width => 20, -length => 370, -anchor => 'w', -from => 0, -to => 100, -blocks => 0.1, -colors => [0, 'blue', 100], )->pack(-side=>'left', -fill=>'both'); $progress->value($position); MainLoop(); #--------------------------------------------------------------------- sub get_files { my $i; while ($i <= 10 ) { $percent_done = int(($i/10) * 100); $progress->value($percent_done); $progress->update; $i++; sleep(1); $message = "Loop number $i."; } }

In reply to Progress bar in Tk by Anonymous Monk

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.