How can I create a Tkinter GUI stop button to interrupt a function that takes a lot to be executed. I would like to be able to just hit the stop button and then it interrupts the main function and cleans all GPIOs. It would be cool if I could do it using the tk.after() instead of using threads. Thank you!
from Tkinter import *
def main_function():
#a function that open and closes GPIOs on a RPi, and takes hours to be
#fully executed.
root = Tk()
root.title("Title")
root.geometry("500x500")
app = Frame(root)
app.grid()
start = Button(app, text="Start Scan",command=scanning)
stop = Button(app, text="Stop",command="break")
start.grid()
stop.grid()
Once I hit the start I need to wait the main function to end to be able to click the stop button.