in reply to Re: clunky Tk GUI
in thread clunky Tk GUI
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: clunky Tk GUI
by zentara (Archbishop) on Jan 21, 2009 at 16:48 UTC | |
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 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 | [reply] [d/l] |
by Anonymous Monk on Jan 22, 2009 at 14:33 UTC | |
Hi, I think you mean my %hash;not my $hash; | [reply] [d/l] [select] |
by zentara (Archbishop) on Jan 22, 2009 at 14:48 UTC | |
I'm not really a human, but I play one on earth Remember How Lucky You Are | [reply] |
by honyok (Sexton) on Jan 23, 2009 at 22:25 UTC | |
BJ | [reply] [d/l] |
by zentara (Archbishop) on Jan 24, 2009 at 05:40 UTC | |
I'm not really a human, but I play one on earth Remember How Lucky You Are | [reply] |
by honyok (Sexton) on Jan 27, 2009 at 05:51 UTC | |
by zentara (Archbishop) on Jan 27, 2009 at 12:53 UTC | |
|