Oct-01-2021, 02:55 AM
(This post was last modified: Oct-01-2021, 05:18 AM by Yoriz.
Edit Reason: Added prefix
)
Hello all,
I am trying to write a function for a tkinter button that when toggled begins running a continuously looping function until the same button is toggled again. The code below is where i started. When the button is pressed "looping" gets continuously printed until i close the window. However, I'd rather the function stop being called after the same button is pressed again. Thanks in advance!
I am trying to write a function for a tkinter button that when toggled begins running a continuously looping function until the same button is toggled again. The code below is where i started. When the button is pressed "looping" gets continuously printed until i close the window. However, I'd rather the function stop being called after the same button is pressed again. Thanks in advance!
from tkinter import * def close(): win.destroy() def loopFunction(): print("looping") win.after(1,loopFunction) win = Tk() InitButton = Button(win,text='Loop Function',command= loopFunction , bg = "bisque2") #,bg='grey') InitButton.grid(row=0, column=0, pady = 5) win.protocol("WM_DELETE_WINDOW", close) win.mainloop()