Theo_124 has asked for the wisdom of the Perl Monks concerning the following question:
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.
And of course I define all of the various widgets and callbacks that are contained in each of these screens.Frame0 : main menu screen Frame1 : option 1 screen Frame2 : option 2 screen
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/tk program structure for multiple screens
by Khen1950fx (Canon) on Apr 02, 2008 at 06:36 UTC | |
|
Re: Perl/tk program structure for multiple screens
by Anonymous Monk on Apr 02, 2008 at 04:53 UTC | |
|
Re: Perl/tk program structure for multiple screens
by zentara (Cardinal) on Apr 02, 2008 at 13:58 UTC |