1# specific problem and answer
2import threading
3import tkinter
4
5def Loop(run):
6 while run():
7 # infinite loop
8
9run = True
10main = tkinter.Tk()
11threading.Thread(target=Loop, args=(lambda:run,)).start()
12main.mainloop()
13run = False # thread will be stopped after Tkinter GUI closed
14 # or use other trigger
15
16# alternatively, you might want to read about daemon instead