import threading
import tkinter
from tkinter import *
flag = False
def terminate_prog():
global win3, mylabel
global flag
flag = True
win3.destroy()
def loop_func():
global flag, mylabel
while True:
if flag:
break
else:
mylabel.config(text="Loop")
global mylabel
global button_win3_end
global win3
win3 = tkinter.Tk()
win3.geometry("700x500")
mylabel = Label(win3, text="Text")
mylabel.pack()
check_thread = threading.Thread(target=loop_func)
check_thread.start()
button_win3_end = Button(win3, text="Exit", command=lambda: terminate_prog)
button_win3_end.place(x=40, y=400)
win3.mainloop()
In the code, there is a label in the window and 'loop_func' function called by check_thread that is used to continuously run the loop. When I click on exit, the loop terminates because flag is True, but window is not destroyed and the program does not terminate. terminate_prog function should terminate the program but it does not.