Do you expect (or need) to be able to do anything with GUI #1 while GUI #2 is running? If it's okay for GUI #1 to "freeze" (be idle, not respond to any user input events) while you use GUI #2, then Grandfather's suggestion, using backticks or a system() call in #1 to run #2 as a separate program, should work out fine. Execution in #1 will wait until #2 exits.

But if you need to use both GUI's while #2 is on the screen, then you'll want a modified version of #2 that has everything except the Mainloop call. If all the widget creation stuff is not already in a sub, just wrap it all in a sub. Put "1;" at the end of the script.

Then, add the appropriate "require" statement to the #1 script, and the button in GUI #1 that brings up #2 just has to call the one sub that creates all the widgets (including #2's mainwindow). Oh, and if #2 has a button that invokes "exit", change that to just destroy #2's mainwindow, so that #1 doesn't get shut down as well.

update: one last point to consider: if you've been good, and already have "use strict" in both scripts and are not mucking around with global variables, then folding the scripts together this way into a single program should work out just fine. But if you haven't been good, this exercise may very well educate you in the wisdom of stricture. (I know that with Tk scripts, it can be hard to avoid the use of globals in many situations. But it can be done.)

(one more update: If you happen to be using any unix-like OS, you could have both GUI's running as separate programs and both responding to user input, by passing the #2 command line string to "system()" with an ampersand at the end of the line, to run that program in the background -- e.g.  system( "gui2 arg1 arg2 &" );. I'm not a windows user, so I don't know if this works for windows, but maybe it does, or maybe there's something for windows that is equivalent to running a background job. This could also mean that every time you push that button in #1, you start another #2 window running -- you could have any number of secondary GUI's going on at once, which might be very good, or very bad, depending...)


In reply to Re: Starting another Tk GUI MainLoop by graff
in thread Starting another Tk GUI MainLoop by Ace128

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.