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.

What does that mean?

Maybe this helps TK::ProgressBar Color update , to track progress, you simply increment a counter

#!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::ProgressBar; my $mw = tkinit; my @files = 1 .. 123; my $status_var = 0; my $start_count = 0; my $finish_count = int @files; my $end_count = $finish_count - ( $finish_count / 3 ); my $middle_count = int( $finish_count / 3 ); my $resolution = 1; my $blocks = 10; $mw->ProgressBar( -borderwidth => 2, -relief => 'sunken', -width => 20, -padx => 2, -pady => 2, -variable => \$status_var, -colors => [ $start_count => 'green', $middle_count => 'yellow' , $end_count => 'red', ], -resolution => $resolution, -blocks => $blocks, -anchor => 'w', -from => $start_count, -to => $finish_count, )->pack( -fill => 'both', -expand => 1 ); $mw->Scale( -from => $start_count, -to => $finish_count, -variable => \$status_var, )->pack; $mw->raise; for my $file ( @files ){ some_thing( $file ); $status_var++; $mw->update; } $mw->Button( -text => 'Go', -command => [ \&status_from_zero, \$status_var ], )->pack; MainLoop; sub status_from_zero { use Time::HiRes qw( usleep ); $status_var = 0; for( 1 .. 200 ){ $status_var++; usleep( 1000 ); #~ $Tk::widget->parent->update; $Tk::event->W->parent->update; } } sub some_thing { use Time::HiRes qw( usleep ); usleep( 1000 ); } __END__

In reply to Re: Progress bar in Tk by beech
in thread 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.