In Perl Tk the MainLoop is not so much something that is called, but it is the event handler loop that keeps it all going. As someone else pointed out, you can destroy the $mw ( Main window ) object and then continue. But as for a pure return leaving the GUI running? No. The event loop responds to all the GUI events and also permits you to put your own callback's into the queue to be handled by several different stages of the event processing loop. It also has a delay mechanism and a periodical event timer mechanism as well.

If what you want is to put little dialogs windows in various places and then continue after they are handled, then that is easy. Here is something adapted from some code I am working on right now:

#!/usr/bin/perl -w use strict; use warnings; use Tk; my $mw = MainWindow->new(); $mw->withdraw(); my $ftp_warn = $mw->messageBox( -title => 'Silly message', -message => "We are displaying a silly message, do you wish to conti +nue?", -type => 'YesNo', -icon => 'question', ); if ( $ftp_warn eq 'No' ) { exit; } else { my $msg2 = $mw->messageBox( -title => 'Really?', -message => "We displayed silly message and you wish to continue?" +, -type => 'OK', -icon => 'question', ); exit; }
That code will run.

Now if you were to replace the else clause with a call to a function, then you can execute other code. This is naturally quite trivial, because in a Tk application you will have some sort of user interface that appears in the MinWindow (the $mw that I hid with the $mw->withdraw method call) whioch will direct what is to be done.

Tk is a very useful GUI tool, there are a number of heavy Tk users here in the Monastery. You will find it explained in the docs or you could look at Mastering Perl/Tk" by Lidie and Walsh published by O'Reilly.

jdtoronto


In reply to Re: Perl Tk-How to return from 'MainLoop' by jdtoronto
in thread Perl Tk-How to return from 'MainLoop' by herby1620

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.