[Edited] I am trying to destroy a Toplevel object from inside its widget's callback, but it seems that it cannot be destroyed until the callback function is done running. Below is the essence of my script:
from tkinter import *
from time import sleep
import gnupg
w = Tk()
t = Toplevel()
lbl = Label(t, text="blah blah")
lbl.grid(row=0, column=0)
lbl.bind("<Button-1>", func_a)
def func_a(event):
event.widget.master.destroy()
gpg = gnupg.GPG()
plaindata = b'Some data'
encrdata = plaindata
for i in range(20):
encrdata = gpg.encrypt(encrdata,
symmetric=True,
passphrase='something',
recipients=None).data
print("func_a is done")
w.mainloop()
As you can see, I am using a gpg symmetric encryption 20 times, which takes ~20 seconds. What I expected to see when clicking on Label (object "lbl") is the entire Toplevel window (object "t") immediately disappearing and then 20 seconds later message "func_a is gone" being printed in the terminal. Instead, Toplevel window became unresponsive for 20 seconds (I could still move it but all of its widgets kinda froze) before finally disappearing the same time the aforementioned message was printed.
Could you please explain why the parent Toplevel did not get destroyed immediately? Does it have to do with the function being called as a widget's callback? And how can I force the parent window to be killed before other content in the callback function is completed?