from tkinter import *
import threading, time
run = True
def clik():
while run:
print('loop')
time.sleep(2)
Potok = threading.Thread(target = clik, daemon=True)
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()
print('Конец кода')
from tkinter import *
import threading, time
run = True
def clik():
while run:
print('loop')
time.sleep(2)
Potok = threading.Thread(target = clik, daemon=True)
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()