【发布时间】:2021-04-08 02:13:48
【问题描述】:
我在 Python Tkinter 中有这个应用程序。有一个 Python 文件,它是一个主菜单。当我单击主菜单中的一个选项时,它会导入一个带有创建新窗口的代码的 python 文件(由于某些原因,新窗口不能使用Toplevel)。所以当我关闭主菜单时,它应该关闭所有其他窗口。
这是我的主菜单代码:
from tkinter import *
root = Tk()
root.geometry("600x600")
def newWindowImport():
import file1
def newWindowImport2():
import file2
newWindow = Button(text="new window", command=newWindowImport).pack()
newWindow2 = Button(text="new window", command=newWindowImport2).pack()
# Here is there a way so that when I exit it destroys the Main Menu as well as the opened windows
exitBtn = Button(text="Exit", command=root.destroy())
root.mainloop()
我尝试了root.destroy 方法,但它只破坏了主菜单,而不是所有的窗口。有没有办法让我退出主菜单时它会破坏主菜单以及打开的窗口?如果我要使用Toplevel - 我将如何在单独的文件中使用它?
【问题讨论】:
-
请编辑您的问题,并附上这些导入文件中的内容示例——让人们了解为什么使用
Toplevel对您不起作用。
标签: python python-3.x tkinter logic