How to translate these codes into GUI

Hi all,

I have a data structure like as follow:

myarray=[
[{“A”=>1}],
[{“B”=>2},{“C”=>3,“D”=>4}],
[{“E”=>5,“F”=>6},{“G”=>7},{“X”=>10,“Y”=>20,“Z”=>30}]
]

And I can control the output of each key and value using the following
blocks via gets:

myarray.each do|ary|
ary.each do |hsh|
hsh.each_pair do |k,v|
puts k
gets

      puts v
      gets
    end#
end#hsh

end#ary

My question here: how do I translate these codes into a GUI/Tk so that
when I press “Next_button”, the script will print out the key, press
“Next_button” again it will print out the corresponding value, so on so
forth. In other words, I want to print out each k following by v by
pressing “Next_button”.

Thanks,

You need something which holds the current state of the processing.
There are several ways on how to encode this “something”. For example,
you could use a Tk variable for this. Another possibility is that you
create a class deriving from the Tk button class, which has a data
member holding the state.

How you implement this state, is also a matter of taste. In your case,
it might be easiest to generate initially the complete list of values
going to be output (basially, everything flattened into one array), plus
an index into this list (pointing to the element which should be output
next). With this, you can even easily (if needed) implement a “Previous
button” too.

Ronald

Hi Ronald,

Thank you for the comments.

I think I come out with the solutions. Please see another post,
entitled"how to stop a process".