My app has the following structure:
import tkinter as tk
from threading import Thread
class MyWindow(tk.Frame):
    ...  # constructor, methods etc.
def main():
    window = MyWindow()
    Thread(target=window.mainloop).start()
    ...  # repeatedly draw stuff on the window, no event handling, no interaction
main()
The app runs perfectly, but if I press the  X (close) button, it closes the window, but does not stop the process, and sometimes even throws a TclError.
What is the right way to write an app like this? How to write it in a thread-safe way or without threads?
 
    