0

I am working with tkinter and within the __init__() method of my Windows class, where I launch two threads that execute a method.

My problem is that I can't figure out where to call .join() so that those threads don't continue their execution once the main window is destroyed through Tk().destroy() method.

martineau
  • 119,623
  • 25
  • 170
  • 301
Fede Brun
  • 1
  • 2
  • ***call .join()so that those threads don continue***: `.join()` don't terminate a `Thread`. Read [terminate an Thread controlled](https://stackoverflow.com/a/43686996/7414759) – stovfl May 06 '20 at 17:32
  • When you create the Threads, make them "daemonic" before starting them. This will cause them to be automatically terminated when the main thread exits. It's mentioned in the [Thread documentation](https://docs.python.org/3/library/threading.html#threading.Thread). – martineau May 06 '20 at 17:45

1 Answers1

0

Tkinter.Tk().mainloop() is blocks the program from continuing while the screen updates. After calling Tk().destroy(), it will unblock and continue the program as normal, allowing you to call thread.join() there. Here as a demo of for code executing after:

from tkinter import Tk

root = Tk()

def f():
    root.destroy()

root.after(3000,f)
root.mainloop()
print("Join Thread Here")
Misha Melnyk
  • 409
  • 2
  • 5