Greetings,

I apologize for taking everyone's time with my silly questions, but I'm having a very difficult time figuring out how to structure a Perl/tk program that is more than a single screen. I'm sure someone has already dealt with these issues before, and I'm looking for some suggestions (dare I say best practices).

For example:

For a simple program that consists of a main menu with two options (which each lead to very simple data entry screens), this is what I believe I would need. To make my language less ambiguous, I will assume that each "screen" consists of a single frame.

It looks like I should define my frames first - one for each screen.

Frame0 : main menu screen Frame1 : option 1 screen Frame2 : option 2 screen
And of course I define all of the various widgets and callbacks that are contained in each of these screens.

Then, I have a subroutine that takes two parameters, the existing frame and the new frame. This is the frame-switcher. It packForget(s) the existing frame and pack(s) the new frame. This frame-switcher will be called from the main menu (to select one of the two screens) or from either of the data entry screens when the user needs to get back to the main menu.

But before I display the new frame, I really need to clear all the values that might exist in all the widgets of that screen. So I need a way to either clear all the values of the widgets on that screen before re-displaying it or a way to delete the widgets and re-define/re-pack them onto that frame.

Which of these options makes the most sense? Or is there a third (or fourth) option. I apologize if this is confusing (it is to me).

To make matters more "interesting", one of my screens consists of a variable number of frames (depending on how many "items" the user added to an invoice). So I need a way to re-set it back to 1 item before I re-display it. I don't want to have to pull all my variables out from the guts of the GUI and make them global just to clear them.

It seems difficult to avoid global variables with GUI programming, but I believe I should... right? It appears that all my variables will need to be visible from the frame-switcher (which will need to clear them somehow).

I'm having a very hard time letting go of the sequential execution of statements that I grew up with and trying to define everything at once and then just let go with a single MainLoop working it's magic.

Any ideas or examples of multi-screen programs and how someone handled these issues?

Many thanks for any suggestions.

- confused and befuddled


In reply to Perl/tk program structure for multiple screens by Theo_124

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.