tkinter Askstring 在其可见性更改之前被删除

Max*_*ing 4 string tkinter python-3.x simpledialog tkinter-entry

我正在尝试制作一个弹出窗口,人们可以在其中填写输入框中的字符串。我已经经历了很多例子,但它不起作用。

我正在尝试这样做:

    var_entry = simpledialog.askstring("Test", "Test")
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

_tkinter.TclError: window ".!_querystring" was deleted before its visibility changed
Run Code Online (Sandbox Code Playgroud)

提前致谢!

编辑:发布错误的错误消息

Joh*_*n D 7

我知道这是一个旧线程,但我遇到了同样的问题,到目前为止还没有找到根本原因。

但是,如果其他人需要它,此解决方法对我有用:

#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()
Run Code Online (Sandbox Code Playgroud)