## This would be my main script, and I'll keep it
## fairly simple. Notice that I'm using a module
## called ContinueBox. ContinueBox is trivial, but let's
## say that ContinueBox maps to the your child script. It
## contains the functionality that you want to be easily
## reused.
use strict;
use Tk;
use ContinueBox;
my $mw = MainWindow->new;
my $dialog = $mw->ContinueBox;
$mw->Button(
-text => "start child",
-command => sub {
my $result = $dialog->Show;
## I'm not doing much with the result here
## but I could use it terminate the entire
## script if I wante if the result was "Exit".
print "$result\n";
})->pack;
MainLoop;
####
package ContinueBox;
use Tk;
use base qw(Tk::Toplevel);
Tk::Widget->Construct('ContinueBox');
sub Populate
{
my ($cw, $args) = @_;
$cw->SUPER::Populate($args);
$cw->{Result} = "";
## SETUP CONTROLS
$cw->Label(
-text => "Would you like to continue?"
)->pack(-side => 'top');
my $bFrame = $cw->Frame->pack(-side => 'bottom');
$bFrame->Button(
-text => "Continue",
-command => sub { $cw->{Result} = "Continue"; }
)->pack(-side => 'left');
$bFrame->Button(
-text => "Exit",
-command => sub { $cw->{Result} = "Exit"; }
)->pack(-side => 'left');
$cw->protocol(WM_DELETE_WINDOW => sub {
$cw->{Result} = "Exit";
});
$cw->withdraw;
}
sub Show {
my $cw = shift;
$cw->{Result} = "";
$cw->deiconify;
$cw->waitVariable(\$cw->{Result});
$cw->withdraw;
return $cw->{Result};
}
1;
####
package ContinueBox;
use Tk;
use base qw(Tk::DialogBox);
Tk::Widget->Construct('ContinueBox');
sub Populate
{
my ($cw, $args) = @_;
$args->{-buttons} = [qw/Continue Exit/],
$args->{-default_button} = "Continue";
$cw->SUPER::Populate($args);
$cw->add("Label", -text => "Do you want to continue?")->pack;
$cw->protocol(WM_DELETE_WINDOW => sub {
$cw->Subwidget('B_Exit')->invoke;
});
}
1;