#! c:\perl\bin\perl.exe use Tk; use Tk::ProgressBar; use strict; # Had to turn off because of how I build %Items use warnings; my $pause = 0; my $count = 0; my %Items; # Just to build the hash. It's actualy a nest of other data under it. # {'status'}.. {'message'}.. {'tasks'}.. {'history'}[$histcount++].... until ($count >= 10 ) { $Items{$count}{'status'} = "1"; $count++; } my $mw = new MainWindow(-title => "demo"); $mw->configure(-menu => my $menubar = $mw->Menu); my $control = $menubar->cascade(-label => "~Control"); $control->command( -label => "Run", -command => \&a_long_process ); $control->command( -label => "Pause", -command => sub {$pause = 1;} ); $control->command( -label => "Resume", -command => sub {$pause = 0; } ); $control->command( -label => "Run", -command => sub{exit;}); my $F_Status = $mw->Frame( -relief => 'groove')->pack(-side => 'bottom', -expand => 1, -fill => 'x'); $F_Status->Label(-text => ' Status:')->pack( -side => 'left'); $F_Status->Label(-textvariable => \$pause )->pack( -side => 'left'); my $F_Status_Target; # Build P-Bars foreach (keys %Items ) { $F_Status_Target = $mw->Frame( -relief => 'raised', -borderwidth => 1); $F_Status_Target->pack( -side => 'bottom' ); $F_Status_Target->Label( -text => $_, -width => 5 )->pack( -side => 'left'); $F_Status_Target->ProgressBar( -from => 0, -to => 500, -blocks => 500, -colors => [0, 'blue'], -variable => \$Items{$_}{'p_bar'} )->pack( -side => 'left'); $Items{$_}{'p_bar'} = 10; # Initial set } MainLoop; sub a_long_process { foreach $_ (keys %Items ) { print "$_\n"; sleep 5; # In my case, map a drive, copy a file, schedule a task.... $Items{$_}{'p_bar'} = 100; $mw->update(); sleep 2; # In my case, map a drive, copy a file, schedule a task.... $Items{$_}{'p_bar'} = 300; $mw->update(); sleep 4; # In my case, map a drive, copy a file, schedule a task.... $Items{$_}{'p_bar'} = 500; $mw->update(); if ($pause) { while(1) { select(undef,undef,undef,0.1); last unless $pause; $mw->update(); } } } }