Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 browsing the Monastery: (1)
As of 2024-04-25 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found