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. Advertisements

  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. Advertisements

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. k2riddim

    Problem with tkinter mainloop

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

    detect tk mainloop

    John Hunter, Jan 26, 2005, in forum: Python
    Replies:
    0
    Views:
    401
    John Hunter
    Jan 26, 2005
  3. Kreedz
    Replies:
    2
    Views:
    544
    Kreedz
    Sep 12, 2005
  4. Replies:
    0
    Views:
    554
  5. zxo102
    Replies:
    10
    Views:
    930
    zxo102
    Aug 8, 2006
  6. [david]

    wxPython before MainLoop

    [david], Aug 9, 2007, in forum: Python
    Replies:
    23
    Views:
    1,385
    [david]
    Aug 21, 2007
  7. globalrev

    question about the mainloop

    globalrev, Apr 21, 2008, in forum: Python
    Replies:
    6
    Views:
    851
    globalrev
    Apr 22, 2008
  8. Peter Otten
    Replies:
    2
    Views:
    865
    John McMonagle
    Mar 15, 2009
Loading...