in reply to Tk::Entry textvariable and array elements
The point is - when you did -textvariable=>$arr[$i], Tk used those scalars as a references to Entry contents.
But after your assignment to entire @data something, you have new different scalars in there!
But if you'll do
your code will work as you desired to!@data[0..$#data] = ( 'a'..'x');
Below is working code snippet for you to try:
Best wishes,use strict; use Tk; use Tk::Table; my $mw = tkinit; my @data = ( "init", "init", "init", "init" ); my $tableWidget = $mw->Table->form(-top=>'%0', -bottom=>['%100',-20], +-left=>'%0', -right=>'%100'); my $btn = $mw->Button( -command=>\&update, )->form(-top=>$tableWidget, -bottom=>'%100', -left=>'%0', -right=>'%10 +0'); my @headers = 'a'..'k'; my $e; 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 ); } } sub update { @data[0..$#data] = ( 'a'..'x'); } MainLoop;
|
|---|