Tkinter:使用顶层窗口的存在作为条件

2024-05-23 17:45:27 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我知道已经有一个问题在回答这个问题,但是在答案中实现它的方法不清楚,我无法让它工作

我想检查“top”是否存在,但我在下面执行此操作的方式会返回一个名称错误

def createTop():
    top = tk.Toplevel()
    top.title(string="Admin Access")
    top.geometry(newGeometry="300x90")
    top.resizable(width=False, height=False)
    top.lift(aboveThis=root)
    top.update_idletasks()


def TopExists():
    test = print(tk.Toplevel.winfo_exists(top))
    if test == 1:
        print('Exists')
    else:
        print("Does not exist.")

如果你能帮我找到合适的方法,我将不胜感激


Tags: 方法答案test名称falsestringtitletop