Coding Tutorials Hub

Learn coding with simple code, clear explanations, and examples

Python TKinter GUI - Checkbutton Widget get status

📄 Code


import tkinter as tk

def get_status():
    value = status.get()
    if value == 0:
        label.config(text="not checked")
    if value == 1:
        label.config(text="checked")

# Create the main window
root = tk.Tk()
root.title("Tkinter-GUI checkbutton Tutorial")
root.geometry("300x150")

# Create a check button
status = tk.BooleanVar()
check = tk.Checkbutton(root, text="Accept terms", variable=status)
check.pack(pady=10)

# Create a button
button = tk.Button(root, text="Click to get checkbutton status", command=get_status)
button.pack(pady=5)

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

# Run the application
root.mainloop()
        
💡 Output