in reply to how to fork & join in tk?
Tk::IO lets you run another process and get callbacks for its output and completion.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1188639 use strict; use warnings; use Tk; use Tk::IO; my $status = 'startup'; my $mw = MainWindow->new; $mw->geometry('+700+400'); $mw->Label( -textvariable => \$status, -font => 'Times 30', -fg => 'navy', -height => 3, -width => 20, )->pack; my $button = $mw->Button(-text => "step one", -command => \&fun, -font => 'Times 30', )->pack; MainLoop; sub fun { $button->configure(-text => "step two" ); Tk::IO->new( -linecommand => sub {$status = shift()=~tr/\n//dr}, -childcommand => sub { $button->configure(-text => "step three" ); }, )->exec("echo start sleep; sleep 2; echo sleep ended"); }
|
|---|