Tạo button gọi hàm đóng cửa sổ: win.destroy() hoặc win.quit().
Các bước
Nhập tkinter, tạo cửa sổ.
Hàm close() gọi win.destroy() hoặc win.quit().
Tạo Button với command=close.
Chạy mainloop.
Ví dụ
from tkinter import *
win = Tk()
win.geometry("700x350")
win.title("Click the Button to Close the Window")
def close():
win.quit() # hoặc win.destroy()
Button(win, text="Close the Window", font=("Calibri",14,"bold"), command=close).pack(pady=20)
win.mainloop()
Kết quả
Click button "Close the Window" → đóng ứng dụng.

Lưu ý: win.quit() thoát mainloop nhưng có thể vẫn chạy nền. win.destroy() hủy hoàn toàn mainloop và tất cả widget.