Since tkinter isn't thread-safe, I often see people use the after
method to queue some code for execution in the main thread. Here's an example:
import tkinter as tk
from threading import Thread
def change_title():
root.after(0, root.title, 'foo')
root = tk.Tk()
Thread(name='worker', target=change_title).start()
root.mainloop()
So instead of executing root.title('foo')
directly in the worker
thread, we queue it with root.after
and let the main thread execute it. But isn't calling root.after
just as bad as calling root.title
? Is root.after
thread-safe?