Coding Tutorials Hub

Learn coding with simple code, clear explanations, and examples

Python TKinter GUI - Button Widget

📄 Code


import tkinter as tk

def change_text():
    button.config(text="You clicked the button")

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

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

# Run the application
root.mainloop()
        
💡 Output