I am a beginner in Python. I use to code with Tkinter. I want to improve my programs with the extension "threading". However, in some of my programs, if i leave the Tkinter window, the program is still running. I would like to know how stop it. I guess it's the thread which is still running. I tried different ways to close the thread, but the only issue i found is to create an error (and it is not a nice solution according to me) :).
I would like to know if an instruction like the following one exist to stop the thread.
Thread(target=FinTemps).stop()
(I know that 'stop' is not working)
and if it is possible to stop the Thread with a loop 'while', I tried this and i don't understand why it doesn't work :
import tkinter as tk
from threading import Thread as Th
from time import *
global end
end=False
begining=time()
def screen():
global end
while end==False:
chrono=time()-beginning
if chrono<5:
sentence.set("Hey !")
elif chrono<8:
sentence.set("What's up ?")
window=tk.Tk()
window.geometry("{}x{}".format(fenêtre.winfo_screenwidth(), window.winfo_screenheight()))
window.title("Test Tkinter & Thread")
sentence=tk.StringVar()
sentence.set("none")
GreatTitle=tk.Label(window, textvariable=sentence, width=500)
Th(target=screen).start()
GreatTitle.pack(expand=1)
window.mainloop()
end=True
Thank you ;) (And sorry if my english is not wonderful (I'm french) or if my code or explainations weren't very understandable or without following traditional presentation).
Have a good day :)