Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python - Creating Tkinter buttons to stop/skip a 2D loop [Solved

import tkinter as tk

x = 0
y = 0
array = [[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]
running = True

def start():
    global x, y, running
    x = y = 0
    running = True
    output()

def skip():
    global x, y
    x +=1
    y = 0

def stop():
    global running
    running = False

def output():
    global x, y, running
    try:
        print(array[x][y])
    except IndexError as e:
        if x >= len(array):
            #Run out of lists
            running = False
        elif y >= len(array[x]):
            y = 0
            x += 1
        else:
            raise e
    y += 1
    if running:
        root.after(1000, output)

root = tk.Tk()
btnStart = tk.Button(root,text="Start",command=start)
btnSkip = tk.Button(root,text="Skip",command=skip)
btnStop = tk.Button(root,text="Stop",command=stop)

btnStart.grid()
btnSkip.grid()
btnStop.grid()

root.mainloop()
Source by www.mlink.in #
 
PREVIOUS NEXT
Tagged: #python #Creating #Tkinter #buttons #loop
ADD COMMENT
Topic
Name
9+5 =