Hi all,
I write a simple Tk/GUI with a data structure of an array of array of
hash.
After transforming into an array of array containing 2 elements, I want
to use “Next_button” to print out the nested array sequentially. I try
to use a nested command but it doesn’t work except for the first two
presses. Can anyone help me to improve the codes?
Thanks,
#########################################
require ‘tk’
root=TkRoot.new()
root.title=“Test_Button”
myarray1=[
[{“A”=>1}],
[{“B”=>2},{“C”=>3,“D”=>4}],
[{“E”=>5,“F”=>6},{“G”=>7},{“X”=>10,“Y”=>20,“Z”=>30}]
]
myarray=[]
myarray1.flatten.each do|hsh|
hsh.each_pair do |k,v|
myarray<< [k,v]
end#kv
end#hsh
$mycount=0
button_next=TkButton.new()do
text “Next”
pack()
command proc{
a=myarray[$mycount]
puts a[0]
command proc{ puts a[1] }
$mycount+=1
}
end
Tk.mainloop()