Let's say that I have this tkinter script:
import tkinter as tk
def callback():
new_root = tk.Tk()
new_root.mainloop()
print("Done")
root = tk.Tk()
button = tk.Button(root, text="Click me", command=callback)
button.pack()
root.mainloop()
From my understanding of tkinter, when I press the button, a new window and tcl interpreter should be created. While running callback
, the main window (root
) shouldn't be updated so it should be unresponsive. new_root.mainloop()
is a while True
loop that runs until the second window is closed. Therefore, when I press the button it should create a new window, call .mainloop()
on it and that should make the main window unresponsive. The problem is that that doesn't happen. The main window is responsive even though code execution is stuck inside new_root.mainloop()
.
Also closing the second window doesn't print "Done"
until the rest of the tkinter windows are closed. Why does that happen?
I looked at the source code for tkinter
and _tkinter
but I couldn't find anything useful. I have Python 3.7.9, tcl 8.6
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…