Dear Monks, I want to be able to use an array element
as the -textvariable argument to
$widget->Entry method.

Here's what I tried ...

#global vars @data = ( "init", "init", "init", "init" ); for ( my $row=0; $row<2; $row++ ) { for( my $col=0; $col<$#headers+1; $col++) { my $e; if( $row == 0 ) { $e = $tableWidget->Button ( -relief => "groove", -justify => "left", -text => $headers[$col], -state => 'active', -width => length($headers[$col]) ); } else { $e = $tableWidget->Entry ( -width => $lens[$col], -textvariable => \$data[$col] ); } $tableWidget->put( $row, $col, $e ); } }
... and I would update the displayed textvariables by calling the sub ...
sub update { ... @data = ( / ... big long regex ... /g); ... }
... the problem I am having is that although @data changes the displayed textvariables in my Entry widgets are not changing. So what I had to do was write this ugly code.
... # global variables my $col_0; my $col_1; my $col_2; my $col_3; ... for ( my $row=0; $row<2; $row++ ) { for( my $col=0;$col<$#headers+1;$col++) { my $e; if( $row == 0 ) { $e = $tableWidget->Button ( -relief => "groove", -justify => "left", -text => $headers[$col], -state => 'active', -width => length($headers[$col]) ); } else { if ( $col == 0 ) { $e = $tableWidget->Entry ( -width => $lens[$col], -textvariable => \$col_0); } elsif ( $col == 1 ) { $e = $tableWidget->Entry ( -width => $lens[$col], -textvariable => \$col_1); } elsif ( $col == 2 ) { $e = $tableWidget->Entry ( -width => $lens[$col], -textvariable => \$col_2); } elsif ( $col == 3 ) { $e = $tableWidget->Entry ( -width => $lens[$col], -textvariable => \$col_3); } $tableWidget->put( $row, $col, $e ); } } } ... sub update { ... @data = ( / ... big long regex ... /g); ... $col_0 = data[0]; $col_1 = data[1]; $col_2 = data[2]; $col_3 = data[3]; }
... this works but I bet there is a better way. Please bestow your wisdom. Thank you

In reply to Tk::Entry textvariable and array elements by rbc

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.