How to translate these codes into GUI

Hi all,

I have a data structure like as follow:


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

      puts v


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”.


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.


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".

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs