Sep-09-2021, 11:16 AM
(This post was last modified: Sep-09-2021, 11:38 AM by Yoriz.
Edit Reason: removed unnecessary quote of previous post
)
I am using tkinter. Here is my code. There are two buttons on the GUI. STRAT and STOP. If I press START then a counter up to 30 should be printed on the shell but if I press STOP anytime before the counter reach 30 then the loop should terminate and back to the man loop of GUI. Where should I add thread ?
import time from tkinter import * root = Tk() root.title("Loop Terminate") time.sleep(0.5) # Function button_stop def button_stop(): # If the STOP button is pressed then terminate the loop i = 1 # Function button_start def button_start(): j = 1 while j <= int(30): print("Loop Index = " + str(j)) time.sleep(0.5) j = j+1 # Button START button_start = Button(root, text = "START", padx=53, pady=20, command=button_start) button_start.grid(columnspan=1, row=1,column=0) # Button STOP button_stop = Button(root, text = "STOP", padx=44, pady=20, command=button_stop) button_stop.grid(row=2,column=0)