ส่วนใหญ่มักจะใช้วิดเจ็ต Tkinter Label ในแอปพลิเคชันเพื่อแสดงข้อความหรือรูปภาพ เราสามารถกำหนดค่าวิดเจ็ตป้ายกำกับ เช่น คุณสมบัติข้อความ สี พื้นหลังหรือสีพื้นหน้าโดยใช้ config(**options) วิธีการ
หากคุณต้องการแก้ไขหรือเปลี่ยนวิดเจ็ตป้ายกำกับแบบไดนามิก คุณสามารถใช้ปุ่มและฟังก์ชันเพื่อเปลี่ยนข้อความของวิดเจ็ตป้ายกำกับได้
ตัวอย่าง
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define a function update the label text
def on_click():
label["text"] = "Python"
b["state"] = "disabled"
# Create a label widget
label = Label(win, text="Click the Button to update this Text",
font=('Calibri 15 bold'))
label.pack(pady=20)
# Create a button to update the label widget
b = Button(win, text="Update Label", command=on_click)
b.pack(pady=20)
win.mainloop() ผลลัพธ์
เมื่อคุณเรียกใช้โค้ดข้างต้น จะแสดงข้อความป้ายกำกับและปุ่มในหน้าต่าง

เมื่อคุณคลิกปุ่ม ระบบจะอัปเดตข้อความป้ายกำกับ
