in reply to Tk for start/stop of endless loop?
use Tk; use Tk::Button; use Tk::Label; use Tk::Text; my $foo = 0; my $break = 0; my $mw = tkinit; my $lbl1 = $mw->Label(-textvariable, \$foo)->pack(); my $txt1 = $mw->Text(-height, 1 )->pack(); my $btn1 = $mw->Button( -text, 'Start', -command, \&foo )->pack; MainLoop; #sub below the main sub foo { $btn1->configure(-text, 'Type quit in the text box to stop!'); while(1){ $foo++; $break = $txt1->get('0.0', 'end'); last if $break =~ /quit/ig; $mw->update; } $btn1->configure(-text, 'Start'); }
|
|---|