Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: why won't Tk textvariable take a reference to an array element?

by serf (Chaplain)
on Jan 24, 2006 at 18:52 UTC ( #525284=note: print w/ replies, xml ) Need Help??


in reply to why won't Tk textvariable take a reference to an array element?

As long as you do the:

@status_label = ( "abc", "def" );
before the:
my $label1 = $frame_top->Label( -textvariable => \$status_label[0] ) ->grid( -row => 1, -column => 1 );
It will work.

Otherwise the

my $label1 = $frame_top->Label( -textvariable => \$status_label[0] )

Update: (thanks runrig - see Re: why won't Tk textvariable take a reference to an array element?)

is referring to $status_label[0] which has not been defined yet.

Make that: "is referring to the original instance of $status_label[0] which is destroyed when you define a new array called @status_label by doing: @status_label = ( "abc", "def" );"

The magical thing is more the fact that the ones which use a reference to a scalar can be defined before the scalar has been populated with data.

The references are setting aside the promise that by the time MainLoop comes around to pack the components of the window together there will be some data sitting in the memory locations referred to by \$entry12, \$entry21 & \$entry22 for MainLoop to pick up and use as values.


Comment on Re: why won't Tk textvariable take a reference to an array element?
Select or Download Code
Re^2: why won't Tk textvariable take a reference to an array element?
by peter.mao (Novice) on Jan 24, 2006 at 19:44 UTC
    Hi Serf,

    yes, that does make it work, but I'm using textvariable so that I can change the text dynamically. Assigning textvariable to a reference to a scalar makes for very messy programming. Is there a way to reference it to an array element that will work?

    I find that if I define @status_label up top, the value of $status_label[0] still doesn't update in the label.

    Perhaps this is a subtlety with MainLoop?

    Peter

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://525284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-04-19 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls