Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: program to print areas in python 
Python :: odoo get inherited models 
Python :: logged_passengers 
Python :: How to separate characters, Numbers and Special characters from given string with python 
Python :: gensim loop through models 
Python :: Common elements in a list(comparing two lists.) 
Python :: python static typing 
Python :: Python | Largest, Smallest, Second Largest, Second Smallest in a List 
Python :: how to set notepad ++ for run python 
Python :: install robobrowser python 3 
Python :: assert isinstance python 
Python :: hashmap in python 
Python :: find element by partial link text selenium python 
Python :: way to close file python with staement 
Python :: Python create time slot within duration 
Python :: python using boolean 
Python :: how to downlaod file using python 
Python :: reveal a defined function in python 
Python :: how to delete lists after using them in python 
Python :: reassign variable python 
Python :: how to create a scoreboard for the top 5 players in python 
Python :: cudf - merge dataframes 
Python :: hidden semi markov model python from scratch 
Python :: can data scientists become software developer 
Python :: PN generator 
Python :: convert step in stl file python OCC.core 
Python :: defining a class in python 
Python :: python decode errors schemes 
Python :: PyQgis Spatial join y attribute 
Python :: Compute p-value 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =