【发布时间】:2018-09-17 14:05:32
【问题描述】:
我在一个程序中有一个按钮可以打开一个顶层窗口。 如果再次按下按钮,我希望销毁旧的顶层并创建一个新的顶层。我已经搜索了几个小时并尝试实施不同的方式,但似乎没有任何效果。
我以各种形式尝试了这些方法:
if toplevel is None or not toplevel.winfo_exists():
toplevel.destroy()
try:
toplevel.destroy()
except:
pass
if toplevel.winfo_exists() == "1":
toplevel.destroy()
我的代码如下所示:
def translate():
#(I would like to check for and close existing toplevels here)
toplevel = Toplevel()
...stuff
非常感谢我能得到的所有帮助!
【问题讨论】:
标签: python tkinter window tk toplevel