If you have followed my previous Tkinter tutorial which is to change the text within a Button once the user has clicked on it then in this tutorial I will create a label widget on the right side of the Button widget and instead of changing the text within the Button, I will change the text within the label widget!
import tkinter as tk from tkinter import ttk win = tk.Tk() win.title("Hello World!") def showHello(txt): #hello.configure(text=txt) # change the text inside the button hello_label.configure(text=txt) # change the text inside the label hello = ttk.Button(win, text="Hello!", command=lambda: showHello("Hello Again")) # create a button hello.grid(column=0, row=0) hello_label = ttk.Label(win, text="Hello!") # create a label hello_label.grid(column=1, row=0) win.mainloop()
Basically, the python program above is the same as the previous one except this time I have created a label widget in which the original text of that label will get replaced once a user has clicked on the Button widget which will call the showHello function to change the text within the label widget.