Tk не может закрыться из-за работающего потока threading
from tkinter import *
import threading as th
isRUNNING = True
def loop():
global isRUNNING
while isRUNNING:
print('loop')
def Exit(event = None):
print('close!')
isRUNNING = False
exit()
thread = th.Thread(target = loop)
thread.start()
FORM = Tk()
FORM.protocol('WM_DELETE_WINDOW',Exit)
FORM.mainloop()
Мне нужно что-бы по закрытию окна поток останавливался.
Ответы (1 шт):
Автор решения: CrazyElf
→ Ссылка
Примерно так можно правильным образом передать сигнал в поток:
def loop():
while not thread.isRUNNING.is_set():
print('loop')
def Exit(event = None):
print('close!')
thread.isRUNNING.set()
exit()
thread = th.Thread(target = loop)
thread.isRUNNING = threading.Event()
thread.start()