There are numerous ways to do what you want, ranging from the nice threads example by BrowserUk, to using "fork-and-exec" in a subroutine. The easiest way is to use the non-blocking Tk::ExecuteCommand module. Here are 2 simple examples, one spawns a new toplevel for the command.
#!/usr/bin/perl -w
use Tk;
use Tk::ExecuteCommand;
use Tk::widgets qw/LabEntry/;
use strict;
my $mw = MainWindow->new;
my $ec = $mw->ExecuteCommand(
-command => '',
-entryWidth => 50,
-height => 10,
-label => '',
-text => 'Execute',
)->pack;
$ec->configure(-command => 'date; sleep 10; date');
my $button = $mw->Button(
-text =>'Do_it',
-background =>'hotpink',
-command => sub{ $ec->execute_command },
)->pack;
MainLoop;
and if you want separate windows, try something like this:
#!/usr/bin/perl -w
use Tk;
use Tk::ExecuteCommand;
use Tk::widgets qw/LabEntry/;
use strict;
my $mw = MainWindow->new;
my $top = $mw->Toplevel;
$top->withdraw;
my $ec = $top->ExecuteCommand(
-command => '',
-entryWidth => 50,
-height => 10,
-label => '',
-text => 'Execute',
)->pack;
$ec->configure(-command => 'date; sleep 10; date');
my $button = $mw->Button(
-text =>'Do_it',
-background =>'hotpink',
-command => sub{
$top->deiconify;
$top->raise;
$ec->execute_command;
$top->withdraw
},
)->pack;
MainLoop;
I'm not really a human, but I play one on earth.
flash japh
|