I have a GUI/Tk which read the data structure in an array of array as
[“Question A”,“explanation for A”],
[“Question”,“explanation for B”],
[“Question C”,“explanation for C”],
[“question n”,“explanation for n”]
When I press “next_button”, the question will appear. If I press “next
button” again, the “explanation” part(second element of the nested
array" will show up.
The issue here is that sometimes the second element of each nested
array, for example, “explanation A”, is quite long, several lines or a
big paragraph. When I press “stop_button”, the script takes quite a
while to respond. What codes are used so that I can let the script to
respond my “stop_button” immediately? Should I or how could I tell ruby
to read the data or each element in a small chunk size instead of whole
element of each array?
Thanks for the comments.
You can add a check inside the slow section of looping code which
updates the GUI and checks for button activity. Usually with a “stop” or
“cancel” button I’ll set a variable which is visible from within the
code loop, and check its value on each iteration.
As for optimising the loop itself, no way to tell without looking at the
Could you please give some sample codes on how to " set a variable which
is visible from within the code loop, and check its value on each
Probably is taking time to show it because fixed loops to refresh the
GUI. As virtuoso say, there must be a way to tell the GUI: “Ey! refresh
right now!”. I’ve never used tk but yes FXRuby. In FXRuby you can attach
a widget to look for the value of a variable in the model. The text in
the widget get refreshed from time to time, I think that that is what
you are doing, you are letting the GUI do his job and it’s fine, but not
for this specific case. In this case you should tell the GUI: “refresh
If you show us your code we can give more targeted advice. If you only
give us generalisations, we will only be able to respond with