Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a Tkinter GUI stop button to break an infinite loop?

Tags:

So I have a Tkinter GUI with two simple options, a start and stop button. I have defined the GUI layout:

from Tkinter import *

def scanning():
    while True:
        print "hello"

root = Tk()
root.title("Title")
root.geometry("500x500")

app = Frame(root)
app.grid()

Here the Start button runs the infinite loop scanning, and the Stop button should break on press:

start = Button(app, text="Start Scan",command=scanning)
stop = Button(app, text="Stop",command="break")

start.grid()
stop.grid()

However, when I hit the Start button, it is always pushed down (assuming because of the infinite loop). But, I cannot click on the Stop button to break out of the while loop.