in reply to Verbose Tk Code
Me again :-)
I had multiple interruptions when composing my original response, "Re: Verbose Tk Code"; I think I finally posted it three or four hours after starting it. I kept thinking that I'd missed something but couldn't tell what that was. Now I see it was the 'with ($left1) {...}' pseudocode.
Firstly, a couple of notes. I wouldn't use spaces for padding text; there are a number of '*pad*' options that would be a better choice, also look for other options, such as '-anchor' and '-sticky', which may be useful. If you want to align widgets vertically, grid() is a better choice than pack(); I don't know if that was your intent here.
Using my earlier suggestions, and the notes above, your pseudocode could be implemented as simply as:
$left1->Label(-text => $_)->pack() for '', qw{Day Week Month Year};
If you haven't used the option database, add "-background => 'cyan'" to the line above. You'll probably want some pack options like "-padx => 5, -anchor => 'w'" (but that's a complete guess as I don't know what layout you're aiming for).
As a more general solution, where you perhaps have complicated options and wanted to store the objects created for later use, something along these lines:
my @widget_order = qw{blank abc xyz}; my %widget_data = ( blank => { opts => ['-text', ''] }, abc => { opts => ['-text', 'Apple Banana Cherry'] }, xyz => { opts => ['-text', 'X Y Z'] }, ); for my $widget (@widget_order) { $widget_data{$widget}{object} = $parent->Widget(@common_options, $widget_data{$widget}{opts}, )->geo_mgr(@geo_mgr_opts); }
That's obviously very rough and incomplete but hopefully gives you an idea.
See also the Widget Demo. The Radiobutton example has a number of blocks of code along the same lines as I have here.
— Ken
|
|---|