#!/usr/bin/perl use Tk; use Tk::ProgressBar; use Time::HiRes; #use warnings; #use strict; my $mw = MainWindow->new(-title => 'ProgressBar example'); $mw->configure(-width=>200, -height=>80); $mw->packPropagate(0); # jetzt wird auf die grösse gepackt my $progress = $mw->ProgressBar( -relief => 'sunken', -borderwidth => 2, -width => 24, -from => 0, -to => 100, -blocks => 20, -colors => [ 0, 'green', 50, 'yellow', 80, 'red'], -variable => \$percent_done )->pack(-fill => 'x', -padx=> 4, -pady=>4); sub go { $_[0]->configure( -state => 'disabled'); for ($i = 0; $i < 1000; $i++) { $percent_done = $i/10; print "$i\n"; #Time::HiRes::sleep(0.3); $mw->update; } $_[0]->configure( -state => 'active'); } $b = $mw->Button( -text => 'Go!', -width => 20 #-command => &go($b) # hier bräuchte ich eine referenz auf den Button )->pack(-side => 'bottom', -pady=>4, -padx=>4); $b->configure( -command => go($b) ); # läuft sofort los MainLoop;