leaving mainloop

S

Shea Martin

I am trying to add an alert pop-up message box to some perl scripts.

sub MsgBox
{
my $msg = shift;
if( length($msg) <= 0 )
{
$msg = "empty message?";
}
my $mw = Tk::MainWindow->new();
$mw->Label(-text => $msg)->pack;
$mw->Button(-text => 'ok', -command => sub{exit})->pack;
&Tk::MainLoop();
}


The problem is, I want to return to my perl script after the the 'ok'
button has been pressed. Obviously sub{exit} is the problem, but I
don't know what else to put? It won't let me put return or last in
there. I am sure that there is a simple way to do this, but I can't see
the forest for the trees.

~S
 
S

Shea Martin

Shea said:
I am trying to add an alert pop-up message box to some perl scripts.

sub MsgBox
{
my $msg = shift;
if( length($msg) <= 0 )
{
$msg = "empty message?";
}
my $mw = Tk::MainWindow->new();
$mw->Label(-text => $msg)->pack;
$mw->Button(-text => 'ok', -command => sub{exit})->pack;
&Tk::MainLoop();
}


The problem is, I want to return to my perl script after the the 'ok'
button has been pressed. Obviously sub{exit} is the problem, but I
don't know what else to put? It won't let me put return or last in
there. I am sure that there is a simple way to do this, but I can't see
the forest for the trees.

~S

FOund my answer:

$mw->Button(-text => 'ok', -command => [$mw => 'destroy'])->pack;

~S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top