tkinter运行完立即关闭窗口
您可以使用root.quit()或root.destroy()方法来关闭Tkinter窗口。root.quit()方法会停止Tkinter事件循环并关闭窗口,而root.destroy()方法会彻底销毁窗口,但必须先停止事件循环。以下是一个简单的示例:
import tkinter as tk
def close_window():
root.destroy()
root = tk.Tk()
label = tk.Label(root, text="Hello World!")
label.pack()
button = tk.Button(root, text="Close", command=close_window)
button.pack()
root.mainloop()
在这个例子中,单击“Close”按钮会调用close_window()函数并关闭窗口。您也可以在代码中的任何其他位置调用root.quit()或root.destroy()方法来关闭窗口。
原文地址: https://www.cveoy.top/t/topic/eDru 著作权归作者所有。请勿转载和采集!