use Time::HiRes qw(sleep); use threads; use threads::shared; use Tk; use Tk::Scrollbar; #====================================================================================================== # Variablen belegen #====================================================================================================== my $durchgaenge:shared = 0; my $infotext:shared = ""; my $die:shared = 0; ######################### T K - T E I L ############################################################### #====================================================================================================== # Hauptfenster #====================================================================================================== $HF = new MainWindow (); $HF->geometry('431x350'); #====================================================================================================== # Frames #====================================================================================================== $FrInfo = $HF -> Frame(-width => 427, -height => 220,-borderwidth => 3, -relief => groove, -bg => black); $FrInfo->place(-x=> 2, -y=> 19); $FrInfo->packPropagate(0); $txtInfo = $FrInfo->Scrolled(Text,-wrap,none,-bg => black,-foreground => white,-scrollbars => 'se', -height => 14,-width => 60, -font => "times -16 bold")->pack(-expand => 'yes', -fill => 'both', -side => 'left'); #======================================================================================================== # Buttons #======================================================================================================== $BtnStart = $HF->Button(-text =>"START", -command => sub {$die = 0;start_thread();$BtnStop->configure(-state=>'active');$timer = $HF->repeat(100,sub{});}, -width => 14, -font =>"Century 10"); $BtnStart->place(-x=> 2, -y=>260); $BtnStop = $HF->Button( -text=>"STOP", -command => sub {$die = 1;$BtnStop->configure(-state=>'disabled');$timer->cancel();}, -width => 14, -state => 'disabled', -font =>"Century 10"); $BtnStop->place(-x=> 140, -y=> 260); $BtnQuit = $HF->Button( -text =>"Quit", -command => sub{exit;}, -width => 14, -font =>"Century 10"); $BtnQuit->place(-x=> 280, -y=> 260); MainLoop(); ######################### ENDE T K - T E I L ########################################################## sub start_thread() { $thread = threads->create( \&start ); $thread->detach; } sub start { while(1) { if($die){return} sleep 0.2; $durchgaenge++; #===== Scrollbalken auf den letzten Eintrag stellen $txtInfo->yview(moveto => '1.0'); #===== Ausgabetext in Ausgabefenster schreiben $txtInfo->insert("end", "$durchgaenge\n"); } }