Coding Tutorials Hub

Learn coding with simple code, clear explanations, and examples

Python TKinter GUI - Label Widget Change text

📄 Code


import tkinter as tk

def change_text():
    label.config(text="text changed")

# Create the main window
root = tk.Tk()
root.title("Tkinter-GUI Tutorial")
root.geometry("500x100")

# Create a label
label = tk.Label(root, text="This is a label", font=("Arial", 14), fg="white", bg="blue")
label.pack(pady=10)

# Create a button
button = tk.Button(root, text="Click to change label text", command=change_text)
button.pack(pady=5)

# Run the application
root.mainloop()
        
💡 Output