use strict; use Tk; use Tk::ProgressBar; # WHY is this required, given the prior line? # If it's not included I get warnings!? my $MAXTIME = 10; my $mw = MainWindow->new; # Main window my $top = $mw->Frame( -background => '#239867', -borderwidth => 2, )->pack(-fill => 'both'); my $lbltxt = $top->Label( -text => 'Just some text', -background => 'white', )->pack(-side => 'right', -padx => 10); my $GoBtn = $top->Button( -text => ' Pop It! ', -command => \&AddItemNew )->pack(-side => 'left', -padx => 10, -pady => 5); my $DoneBtn = $top->Button( -text => ' Exit ', -command => \&Cleanup )->pack(-side => 'right', -padx => 10, -pady => 5); $mw->focus; # Ensure we're talking to the main window MainLoop; # Run the program, watching for events # ---- sub Cleanup { $mw->destroy; } # ---- sub AddItem { my $tp = $mw->Toplevel( -title => ' AddItem' ); # ->pack(-fill => 'both'); my $tpfrm = $tp->Frame( -background => '#22cc00', )->pack(-side => 'top', -fill => 'x'); my $tplbl = $tpfrm->Label( -text => 'Working...', -background => 'white', -foreground => 'black' )->pack(-side => 'top', -padx => 10); my $tpbtn = $tpfrm->Button( -text => 'Close', -command => [$tp => 'destroy'], )->pack(-side => 'top', -padx => 10, -pady => 5); } # ---- sub AddItemNew { my $tp = $mw->Toplevel( -title => ' AddItem' ); # ->pack(-fill => 'both'); my $tpfrm = $tp->Frame( -background => '#22cc00', )->pack(-side => 'top', -fill => 'x'); my $tplbl = $tpfrm->Label( -text => 'Working...', -background => 'white', -foreground => 'black' )->pack(-side => 'top', -padx => 10); $GoBtn->configure(-state => "disabled"); my $progress = $tpfrm->ProgressBar( -width => 20, -length => 100, -anchor => 'w', -state => 'disabled', -value => 0, -from => 0, -to => $MAXTIME-1, -blocks => 1, -colors => [0, 'blue'] )->pack(); for (0..$MAXTIME-1) { $progress->value($_); $progress->update(); sleep 1; } $tp->withdraw; $GoBtn->configure(-state => "normal"); }