เมื่อเราเรียกใช้ ทำลาย() เมธอดด้วยวัตถุหน้าต่าง tkinter จะยุติ mainloop ประมวลผลและทำลายวิดเจ็ตทั้งหมดภายในหน้าต่าง Tkinter ทำลาย() ส่วนใหญ่จะใช้เพื่อฆ่าและยุติล่ามที่ทำงานอยู่เบื้องหลัง
อย่างไรก็ตาม เลิก() สามารถเรียกใช้เมธอดเพื่อหยุดกระบวนการหลังจาก mainloop() การทำงาน. เราสามารถสาธิตการทำงานของทั้งสองวิธีได้โดยการสร้างปุ่ม Object
ตัวอย่าง
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("650x450")
#Define a function for Button Object
def quit_win():
win.quit()
def destroy_win():
win.destroy()
#Button for Quit Method
Button(win,text="Quit", command=quit_win, font=('Helvetica
bold',20)).pack(pady=5)
#Button for Destroy Method
Button(win, text= "Destroy", command=destroy_win, font=('Helvetica
bold',20)).pack(pady=5)
win.mainloop() ผลลัพธ์
การเรียกใช้รหัสจะแสดงหน้าต่างที่มีปุ่มสองปุ่ม "ออก" และ "ทำลาย" ตามลำดับ

คำเตือน − เลิก() จะยุติแอปพลิเคชันอย่างกะทันหัน ดังนั้น ขอแนะนำให้คุณปิดแอปพลิเคชันจากผู้จัดการหลังจากดำเนินการ