Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter askstring deleted before its visibility changed

I am trying to make a popup window where someone can fill in a string in an Entry box. I have gone through many examples, but it doesn't work.

I am trying to this:

var_entry = simpledialog.askstring("Test", "Test")

I get this error message:

_tkinter.TclError: window ".!_querystring" was deleted before its visibility changed

Thanks in advance!

like image 758
Max Koning Avatar asked Oct 21 '25 15:10

Max Koning


2 Answers

I know this is an old thread, but I'm having the same problem and so far haven't found the root cause.

However, this workaround works for me in case anyone else needs it:

#Create a new temporary "parent"

newWin = Tk()

#But make it invisible

newWin.withdraw()

#Now this works without throwing an exception:

retVal = simpledialog.askstring("Enter Value","Please enter a value",parent=newWin)

#Destroy the temporary "parent"

newWin.destroy()
like image 118
John D Avatar answered Oct 23 '25 05:10

John D


I was also able to work around the problem by using the above workaround suggested by John D.

I did some research on this, and it seems that this exception is raised when all of the following conditions are met.

  • The thread that called the simpledialog.askstring method is not the main thread.
  • The Tk window specified in the parent or the Tk window specified in the default_root variable is different from the thread that called the simpledialog.askstring method.

However, I could not come up with a process to deal with this problem. I hope this helps to solve the problem.

like image 25
高見知英 Avatar answered Oct 23 '25 05:10

高見知英



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!