update label text tkinter code example

Example 1: Update label text after pressing a button in Tkinter

#tested and working on PYTHON 3.8 AND ADDED TO PATH
import tkinter as tk
win = tk.Tk()

def changetext():
	a.config(text="changed text!")
    
a = tk.Label(win, text="hello world")
a.pack()
tk.Button(win, text="Change Label Text", command=changetext).pack()

win.mainloop()

Example 2: tkinter change label text

pythonCopyimport tkinter as tk

class Test():
    def __init__(self):
        self.root = tk.Tk()
        self.text = tk.StringVar()
        self.text.set("Test")
        self.label = tk.Label(self.root, textvariable=self.text)

        self.button = tk.Button(self.root,
                                text="Click to change text below",
                                command=self.changeText)
        self.button.pack()
        self.label.pack()
        self.root.mainloop()

    def changeText(self):
        self.text.set("Text updated")        

app=Test()

Example 3: label change in tkinter

stud_input=StringVar()
stud_input.set("Label")
lbl3=Label(add_image_frame,textvariable=stud_input,bg="#ED6244",fg="black").grid(row=4,column=0)
stud_input.set("Changed Label")

Example 4: how to change the text of a label in tkinter

def press():
    Instruction.config(text='Button Pressed')