From: Hidetoshi NAGAI Date: 2004-11-19T16:10:12+09:00 Subject: Re: TkVariable Array? Hi, From: "Kujawa, Greg" Subject: TkVariable Array? Date: Fri, 19 Nov 2004 00:13:35 +0900 Message-ID: > # Create a scale widget for scoring each category > @@scales=Array.new > @@scores=TkVariable.new.to_a > @@category.each_index { |i| > @@scales[i]= > TkScale.new(@@survey) { > from 0 > to 9 > length 400 > orient 'horizontal' > tickinterval 1 > variable @@scores[i] > } > } > > The problem is when I try to return the values of the TkVariable array > (@@scores) all I get back is an empty pair of brackets. Any suggestions > about how I could fix this would be appreciated. I'm only about two weeks > into learning the Ruby language and don't know a lot of Tk, as I am just > googling for sample code to try to guess at this point. Tk widgets can access Tcl's variables only. TkVariable instance is an object to bridge between Ruby and Tcl's variable. For your purpose, you must assign a TkVariable object to each TkScale widget. There are many way to do that. For example -------------------------------------------- @@scales=Array.new @@scores=Array.new @@category.each_index { |i| @@scores[i] = TkVariable.new @@scales[i]= TkScale.new(@@survey) { from 0 to 9 length 400 orient 'horizontal' tickinterval 1 variable @@scores[i] } } ----------------------------------------------------- If you use Ruby 1.8.2, you can use a Tk's Array Varible by the following way. -------------------------------------------- @@scales=Array.new @@scores=TkVariable.new_hash @@category.each_index { |i| @@scales[i]= TkScale.new(@@survey) { from 0 to 9 length 400 orient 'horizontal' tickinterval 1 variable @@scores.ref(i) } } ----------------------------------------------------- TkVariable#ref(idx) method returns a TkVariable object which accesses the receiver TkVariable object's index 'idx'. In this case, "@@scores[i]" returns string value of index i. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)