peter.mao has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to fill in a textvariable in a Tk grid, and it only seems to work if I assign the array elements to scalar variables first.
So it works when I use:
->Label( -textvariable => \$some_scalar )
but not when I do this:
->Label( -textvariable => \$some_array[1] )
In any perl documentation I've seen, they should both be treated as references to scalars, but the text never shows up in the second case. Here's my stripped down code that demonstrates the problem (at least on all the systems I've tried!). It should make a 2x2 grid with "abc" and "def" on the top row, and "1" and "2" on the bottom row. "abc" doesn't show up when I use the array element reference.
What am I overlooking?
Peter
#!/usr/bin/perl use Tk; use strict; use warnings; my (@status_label, @status_value); my ($entry11, $entry12, $entry21, $entry22); #--- my $mainwindow = MainWindow->new(); $mainwindow -> title('testtk'); my $frame_top = $mainwindow ->Frame() ->pack(-side=>'top'); my $label1 = $frame_top ->Label( -textvariable => \$status_label[0] ) ->grid(-row=>1,-column=>1); my $label2 = $frame_top ->Label( -textvariable => \$entry12 ) ->grid(-row=>1,-column=>2); my $value1 = $frame_top ->Label( -textvariable => \$entry21 ) ->grid(-row=>2,-column=>1); my $value2 = $frame_top ->Label( -textvariable => \$entry22 ) ->grid(-row=>2,-column=>2); #--- @status_label = ("abc","def"); @status_value = (1,2); &update_interface(); MainLoop; #--- sub update_interface { $entry11 = $status_label[0]; $entry12 = $status_label[1]; $entry21 = $status_value[0]; $entry22 = $status_value[1]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: why won't Tk textvariable take a reference to an array element?
by serf (Chaplain) on Jan 24, 2006 at 18:52 UTC | |
by peter.mao (Novice) on Jan 24, 2006 at 19:44 UTC | |
|
Re: why won't Tk textvariable take a reference to an array element?
by runrig (Abbot) on Jan 24, 2006 at 19:21 UTC | |
by peter.mao (Novice) on Jan 25, 2006 at 01:59 UTC |