Answer the question
In order to leave comments, you need to log in
Python. How to ensure that a thread is closed by closing a Tkinter window?
Can you please tell me how to ensure that the created separate thread is closed after closing the Tkinter window? This construction works, but in case of an exception crash, window.mainloop() may not be overstepped and the thread will continue to thresh, checked.
from tkinter import *
import threading, time
run = True
def clik():
while run:
print('loop')
time.sleep(2)
Potok = threading.Thread(target = clik)
window = Tk()
window.geometry('300x300+500+500')
window.title("Thread Loop")
btn = Button(window, text="Старт!", command = lambda: Potok.start())
btn.grid(column=1, row=0)
window.mainloop()
run = False
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question