I'm trying to use a button to stop all threads I've created in the for loop. Is there a method to stop threads?
Here's my code:
import threading
import time
from tkinter import *
tk= Tk()
class go(threading.Thread):
def __init__(self,c):
threading.Thread.__init__(self)
self.c = c
def run(self):
while 1 == 1 :
time.sleep(5)
print('This is thread: '+str(self.c))
for count in range(10):
thread = go(count)
thread.start()
btn1 = Button(tk, text="Stop All", width=16, height=5)
btn1.grid(row=2,column=0)
tk.mainloop()