Chúng ta có thể dùng widget Label Tkinter để hiển thị văn bản và hình ảnh. Bằng cách cấu hình widget label, chúng ta có thể thay đổi động văn bản, hình ảnh và các thuộc tính khác của widget.
Để cập nhật động widget Label, chúng ta có thể dùng config(**options) hoặc phương thức cấu hình inline như: để cập nhật text dùng Label["text"]=text; để xóa widget label dùng phương thức pack_forget().
Ví dụ
# Import các thư viện cần thiết
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
# Tạo instance của frame hoặc window tkinter
win = Tk()
# Thiết lập kích thước cửa sổ
win.geometry("700x350")
def add_label():
global label
label = Label(win, text="1. A Newly created Label", font=('Aerial 18'))
label.pack()
def remove_label():
global label
label.pack_forget()
def update_label():
global label
label["text"] = "2. Yay!! I am updated"
# Tạo các nút bấm cho thêm/xóa/cập nhật label widget
add = ttk.Button(win, text="Add a new Label", command=add_label)
add.pack(anchor=W, pady=10)
remove = ttk.Button(win, text="Remove the Label", command=remove_label)
remove.pack(anchor=W, pady=10)
update = ttk.Button(win, text="Update the Label", command=update_label)
update.pack(anchor=W, pady=10)
win.mainloop()
Chạy code trên sẽ hiển thị cửa sổ với một số nút bấm. Mỗi nút có thể dùng để cập nhật/xóa hoặc thêm label trong ứng dụng.
Kết quả

Khi click nút "Update the Label", label sẽ được cập nhật như sau:
