I want to have a tkinter popup which should close after a certain task is complete but as soon as the popup comes up that execution of the code stops there and wait until the popup is destroyed using root.destroy()
Then I tried to use thread and and call that kill_popup() function simultaneously and it killed the popup but also crashed the program by giving an error async handler deleted by the wrong thread tkinter
My understanding about this error is that it comes because my tkinter popup in running on different thread and kill_popup() is on different so when a different thread is trying to kill popup then this error is coming.
I used this method to parallely call that kill_popup() method which doesn't require threading
root.after(1000, lambda : kill_popup())
But in this case when the executing of kill_popup() goes on then tkinter popup freezes and i cannot do anything on popup,so I wanted a solution to this problem as I need a OK button on popup which will perform certain task button on popup.
So can anyone please help me with a solution, I am adding my code as well
def prompt_popup():
global root
global inputText
root = Tk()
root.geometry("750x405")
my_frame=Frame(root)
my_frame.pack(pady=18)
button=Button(my_frame,text="YES",width=8,command=lambda: Action_Pass(),bg="white")
button.grid(row=0,column=0,padx=20)
button=Button(my_frame,text="NO",width=8,command=lambda: Action_Fail(),bg="white")
button.grid(row=0,column=1,padx=20)
root.after(1000, lambda : kill_popup())
root.mainloop()
def kill_popup():
while True:
time.sleep(2)
# condition
root.destroy()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…