วิดเจ็ตป้ายกำกับ Tkinter ใช้เพื่อแสดงข้อความและรูปภาพในแอปพลิเคชัน นอกจากนี้เรายังสามารถกำหนดค่าคุณสมบัติของวิดเจ็ตป้ายกำกับที่สร้างโดยค่าเริ่มต้นในแอปพลิเคชัน tkinter
หากเราต้องการลบป้ายกำกับที่กำหนดไว้ในแอปพลิเคชัน tkinter เราต้องใช้ destroy() วิธีการ
ตัวอย่าง
ในตัวอย่างนี้ เราจะสร้างปุ่มที่อนุญาตให้ผู้ใช้ลบป้ายกำกับออกจากวิดเจ็ต
# Import the required libraries
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the window
win.geometry("700x350")
def on_click():
label.after(1000, label.destroy())
# Create a Label widget
label = Label(win, text=" Deleting a Label in Python Tkinter", font=('Helvetica 15'))
label.pack(pady=20)
# Add a Button to Show/Hide Canvas Items
ttk.Button(win, text="Delete", command=on_click).pack()
win.mainloop() ผลลัพธ์
หากเราเรียกใช้โค้ดข้างต้น จะแสดงหน้าต่างพร้อมวิดเจ็ตป้ายกำกับและปุ่ม

ตอนนี้ ให้คลิกปุ่มเพื่อลบป้ายกำกับออกจากหน้าต่าง
