Heys all,

I'm trying to write a script which involves a large number of pairs of Tk labels and entry boxes. I've written a sub to create each pair, pointing the textvariable to a hash, meaning to create a hash of entry box data keyed on a given key.

However, I do not seem to be able to get information out of the entry box hash - it seems that the data is not being assigned there in the first place. Can anyone see a way to solve this, or if what I am trying to do is not possible, is there an alternative solution? (would a global hash work?)

My code to create each label/entry box pair is below:

sub labelledEntry { my ($_objects, $objkey, $label, $width, $container) = @_; my %objects = %$_objects; $container -> Label( -text => $label ) -> pack( -side => 'left' ); $container -> Entry( -width => $width, -textvariable => \$objects{ +$objkey} ) -> pack( -side => 'right' ); return \%objects; }

and the code I'm using to get data out of the hash (the button code and subroutine to output it) is as follows:

$searchFrame -> Button( -text => 'search', -command => [ \&search, \$o +bjects{searchstr} ] )->pack( -side => 'left' ); sub search { my $text = shift; print STDERR $text; }

Any advice would be appreciated.


In reply to Tk Entry Widgets & Subs by Tanalis

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.