We added a button and a label object to the screen. When we click on the Button object, we changed the text value of the Label with the clicked function.
Python Code: Tkinter change label text with button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from tkinter import * root = Tk() root.title("www.code4example.com") root.geometry("200x100") def clicked(): label["text"]= "clicked" button = Button( text="Click!", command=clicked ).pack() label = Label( text="..." ) label.pack() root.mainloop() |
Output: