我是Python的新学生,如果我的代码太糟糕了,我感到抱歉。网络刮擦发生时,我正在尝试运行“加载”的GIF动画。问题是刮擦完成后,我无法获得顶级窗口来销毁。
我看过许多视频和其他有关此处的帖子均无效。 toplevel.destroy()似乎是常见建议,但不起作用。
class App:
def __init__(self, parent):
self.parent = parent
self.parent.geometry('1000x500+100+100')
self.parent.resizable(width=False, height=False)
self.parent.title('Class Project')
self.canvas1 = tkinter.Canvas(parent, height=500, width=1000)
filename = ImageTk.PhotoImage(file = "background.png")
background_label = tkinter.Label(self.canvas1, image=filename)
background_label.image = filename
def new_window(self):
self.newWindow = tkinter.Toplevel()
self.app = LoadingScreen(self.newWindow)
class LoadingScreen:
def __init__(self, parent):
self.parent = parent
self.parent.title('Loading....')
self.parent.geometry('350x270+100+100')
self.parent.resizable(width=False, height=False)
self.canvas = tkinter.Canvas(parent)
self.canvas.pack()
LoadingScreen.close_window()
def close_window():
toplevel.destory()
toplevel.destory()
NameError:名称“ toplevel”未定义
到目前为止,一切正常,只是无法关闭窗口。