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


In reply to Re: Verbose Tk Code by kcott
in thread Verbose Tk Code by LanX

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.