Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well it's all about hashes, and it's a big topic. I will reccomend you to the tutorials at Data Type: Hash. Now, I will try to give a brief explanation of how it all works.

Instead of storing individual widgets in separate scalars, you can store those scalars in a orderly hash structure, which will allow you to access them by a key. So for instance, say you had 2 pages, and 3 widgets on each page. You could be "clunky" and call them $page1_widget1, $page1_widget2, $page1_widget3, and $page2_widget1, $page2_widget2, $page2_widget3.

You can see how clunky that is. An alternative, would be to store them all in a hash, like

my %hash; # NOT my $hash, unless you want to set it up reference sty +le # then create in loops $hash{$page}{$widget} #like foreach my $page(1..2){ #add the page $hash{$page}{'page'} = $nb->add(......) #fill each page with widgets foreach my $widg( 1..3){ $hash{$page}{$widj} = $hash{$page}{'page'}->Button(.....opt +ions.) } }
Now, all you need to do to access any widget, is the $page and $widget number. For instance, the 2ond widget on page2, would be $hash{2}{2}. ( or $hash{$page}{$widj} )

This is a very simple example of course, and real world apps each need the best hash setup. It sort of is an art that is learned by spending a few afternoons setting up hashes and experimenting. There are 2 great benefits to storing widgets in a hash.

1. It makes accessing and looping thru them easy. You can loop thru all the widgets on page2 for instance.

2. And this comes later.... if you want to put your script into a package or module, the hash is already setup to be blessed. Instead of $hash{$page}{$widj} you would have $self->{$page}->{$widj}.

A whole book could be written on this, so I'm stopping now. Just play around with simple apps, and store things in hashes...it won't take long for you to figure it out.


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^3: clunky Tk GUI by zentara
in thread clunky Tk GUI by honyok

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found