I am developing a tkinter GUI program which has the function of reading each single element in a 2D array. I need three buttons ("Start", "Skip" and "Stop") which have the following functions:
The "Start" button let the program read and print the element inside the array one by one. For example, in the following code, it first print "11", and then "12", and then "13", and then "14", and then "21", and so on until it finishes the whole array.
The "Skip" button allows the program to skip the row which is being read by the program. For example, when the program is printing "12", it will jump to the second row and start to print "21" if I click the "Skip" button.
The "Stop" button stops and whole program.
Current, I can manage the 1D loop case following this example: [TKinter - How to stop a loop with a stop button?][1]. However, a 2D loop is still a huge challenge. Does anyone has the experience? Many thanks!
import tkinter as tk
import time
#Initialize the Root
root= tk.Tk()
root.title("Real time print")
root.configure(background = "light blue")
root.geometry("500x420")
# The array to be printed
array = [[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]
# Define the function to print each element in the array
def do_print():
print("The element inside the array")
time.sleep(1)
return
#Define strat, skip and stop buttons
def start_button():
do_print()
return
start = tk.Button(root, text = "Start", font = ("calbiri",12),command = start_button)
start.place(x = 100, y=380)
def skip_button():
return
skip = tk.Button(root, text = "Skip", font = ("calbiri",12),command = skip_button)
skip.place(x = 160, y=380)
def stop_button():
return
stop = tk.Button(root, text = "Stop", font = ("calbiri",12),command = stop_button)
stop.place(x = 220, y=380)
root.mainloop()