Tkinter Label 위젯을 사용하여 텍스트와 이미지를 표시할 수 있습니다. 레이블 위젯을 구성하여 위젯의 텍스트, 이미지 및 기타 속성을 동적으로 변경할 수 있습니다.
라벨 위젯을 동적으로 업데이트하려면 config(**options) 또는 인라인 구성 방법 예를 들어 텍스트 업데이트의 경우 Label["text"]=text;를 사용할 수 있습니다. 레이블 위젯을 제거하기 위해 pack_forget()을 사용할 수 있습니다. 방법.
예시
# Import the required libraries
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
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"
# Create buttons for add/remove/update the 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() 위의 코드를 실행하면 몇 개의 버튼이 있는 창이 표시됩니다. 각 버튼을 사용하여 애플리케이션에서 레이블을 업데이트/제거하거나 추가할 수 있습니다.
출력

"라벨 업데이트" 버튼을 클릭하면 라벨이 다음과 같이 업데이트됩니다 -
