【发布时间】:2023-03-24 11:35:01
【问题描述】:
我在这部分有两个查询。
在我的代码中,我在根目录下创建了两个框架,第一个框架有“NEXT”按钮可以进入第二个框架。在第二帧有运行按钮,它映射了 close_window 函数。它应该正确关闭所有窗口。但就我而言,没有关闭它。
当我单击“运行”时,我需要关闭所有窗口并需要在同一目录中执行另一个脚本。那有可能吗?
from Tkinter import *
def close_window():
frame2.destroy()
frame1.destroy()
def swap_frame(frame):
frame.tkraise()
root = Tk()
root.geometry("900x650+220+20")
root.title("Testing")
root.configure(borderwidth="1", relief="sunken", cursor="arrow", background="#dbd8d7", highlightcolor="black")
root.resizable(width=False, height=False)
frame2 = Frame(root, width=900, height=650)
frame1 = Frame(root, width=900, height=650)
Button1 = Button(frame1, text="Next", width=10, height=2, bg="#dbd8d7", command=lambda: swap_frame(frame2))
Button1.place(x=580, y=580)
Button2 = Button(frame2, text="Run", width=10, height=2, bg="#dbd8d7", command=close_window,)
Button2.place(x=580, y=580)
frame2.grid(row=0, column=0)
frame1.grid(row=0, column=0)
root.mainloop()
代码有什么问题?
【问题讨论】:
-
如果要关闭整个窗口,为什么只关闭两个框架?
-
如何关闭所有窗口。我认为这是关闭所有窗口的方法。