leaving mainloop

Discussion in 'Perl Misc' started by Shea Martin, Nov 10, 2005.

  1. Shea Martin

    Shea Martin Guest

    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
     
    Shea Martin, Nov 10, 2005
    #1
    1. Advertising

  2. Shea Martin

    Shea Martin Guest

    Shea Martin wrote:
    > 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
     
    Shea Martin, Nov 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Roth

    Re: Tk mainloop()

    John Roth, Jul 20, 2003, in forum: Python
    Replies:
    0
    Views:
    388
    John Roth
    Jul 20, 2003
  2. dan

    Re: Tk mainloop()

    dan, Jul 20, 2003, in forum: Python
    Replies:
    0
    Views:
    463
  3. k2riddim

    Problem with tkinter mainloop

    k2riddim, Nov 30, 2004, in forum: Python
    Replies:
    2
    Views:
    1,407
    k2riddim
    Nov 30, 2004
  4. John Hunter

    detect tk mainloop

    John Hunter, Jan 26, 2005, in forum: Python
    Replies:
    0
    Views:
    331
    John Hunter
    Jan 26, 2005
  5. Kreedz
    Replies:
    2
    Views:
    477
    Kreedz
    Sep 12, 2005
Loading...

Share This Page