เริ่มแรก Tkinter จะสร้างหน้าต่างหรือเฟรมที่มีวิดเจ็ตและป้ายกำกับอยู่ภายใน สมมติว่าเราต้องการปิดหน้าต่าง tkinter ด้วยปุ่ม ปุ่มคือวิดเจ็ต UI ที่สามารถใช้ดำเนินการบางอย่างได้
ตัวอย่าง
ที่นี่ เราจะสร้างปุ่มที่ปิดหน้าต่าง tkinter ในการปิดและยุติล่าม TCL เราใช้ destroy() เป็นหลัก วิธีการ
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("600x250")
#Create a Label
Label(win, text="Press the Close Button to close the window",
font=('Helvetica bold', 11)).pack(pady=20)
#Define a function to close the window
def close_win():
win.destroy()
#Create a Button for closing the window
button= Button(win, text="Close", command=close_win)
button.pack(pady=20)
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีปุ่มที่สามารถเรียกให้ปิดหน้าต่างหรือเฟรมได้

ตอนนี้ให้คลิกปุ่ม "ปิด" เพื่อปิดหน้าต่าง