python change label text with button
from tkinter import *
root = Tk()
# Option 1:
def changeText():
label.set("Updated text")
label = StringVar()
label.set("Test text")
Label(root, textvariable=label).pack()
Button(root, text="Change text", command=changeText).pack()
# Option 2:
def change_text():
my_label.config(text="New text")
global my_label
my_label = Label(root, text="First text")
my_label.pack(pady=5)
my_button = Button(root, text="Change text", command=change_text)
my_button.pack()
root.mainloop()