Having built dozens of desktop applications for American logistics and retail firms, I have spent a lot of time perfecting user interfaces in Python.
One of the most common tasks I encounter is capturing user preferences through checkbuttons.
Whether you are building a shipping calculator or a tax filing assistant, knowing exactly how to get the value of a checkbutton is essential.
In this tutorial, I will show you exactly how I handle Tkinter Checkbuttons to ensure your data collection is seamless and error-free.
Understand the Tkinter Checkbutton Variable
In my experience, the biggest mistake beginners make is trying to get the value directly from the widget itself.
Unlike a text entry, where you might call a get method on the widget, a Checkbutton relies on a “control variable.”
This variable acts as a bridge between the GUI and your Python code, holding the state (checked or unchecked) at all times.
Use BooleanVar to Track States
When I need a simple True or False response, I always reach for the BooleanVar.
It is the cleanest way to handle binary choices, such as whether a user wants to subscribe to a newsletter.
Let’s look at a practical example involving a US-based freight insurance selection.
import tkinter as tk
from tkinter import messagebox
def check_status():
# I use .get() to retrieve the current True/False state
if insurance_var.get():
messagebox.showinfo("Status", "Premium Freight Insurance is Enabled.")
else:
messagebox.showwarning("Status", "Insurance is currently Disabled.")
# Setting up the main application window
root = tk.Tk()
root.title("US Logistics - Shipping Portal")
root.geometry("400x250")
# This is the variable that tracks the checkbutton
insurance_var = tk.BooleanVar()
# I create the checkbutton and link it to our variable
chk_insurance = tk.Checkbutton(
root,
text="Enable Premium Shipping Insurance (US Domestic)",
variable=insurance_var,
pady=20
)
chk_insurance.pack()
# Button to trigger the value retrieval
btn = tk.Button(root, text="Check Enrollment", command=check_status)
btn.pack(pady=10)
root.mainloop()You can see the output in the screenshot below.

In this code, the variable=insurance_var argument is the secret sauce that binds the UI to the data.
Get Integer Values with IntVar
Sometimes, a simple True/False isn’t enough for the backend logic I’m building.
I often use IntVar when I need to pass specific numerical values (like 1 for “Active” and 0 for “Inactive”) to a SQL Server database.
Here is how I implement this for a California State Tax selection tool.
import tkinter as tk
def show_value():
# Retrieving the integer value (1 or 0 by default)
val = tax_var.get()
result_label.config(text=f"Selected Value: {val}")
app = tk.Tk()
app.title("Payroll Calculator - CA Edition")
app.geometry("400x200")
tax_var = tk.IntVar()
# Connecting the IntVar to the widget
chk_tax = tk.Checkbutton(
app,
text="Apply California State Disability Insurance (SDI)",
variable=tax_var,
command=show_value # I trigger the update immediately on click
)
chk_tax.pack(pady=30)
result_label = tk.Label(app, text="Selected Value: 0", font=("Arial", 12))
result_label.pack()
app.mainloop()You can see the output in the screenshot below.

Using the command attribute allows me to get the value the very instant the user interacts with the box.
Customize Values with onvalue and offvalue
I frequently run into scenarios where “1” and “0” don’t fit the data model I am working with. Tkinter allows us to define custom values for the “on” and “off” states using onvalue and offvalue.
I find this particularly useful when I want the Checkbutton to represent specific strings, like “Express” and “Standard”.
Use StringVar for String Retrieval
If you want the Checkbutton to return a string directly, StringVar is the way to go. Here is a scenario for a New York-based food delivery app selecting delivery speed.
import tkinter as tk
def get_delivery_type():
# This will return the string assigned to onvalue or offvalue
current_type = delivery_var.get()
print(f"User selected: {current_type}")
root = tk.Tk()
root.title("NYC Fast-Eats Dashboard")
root.geometry("400x200")
delivery_var = tk.StringVar()
# I set a default value so the variable isn't empty at start
delivery_var.set("Standard")
# Defining custom string values for the states
chk_delivery = tk.Checkbutton(
root,
text="Upgrade to Rush Delivery (Manhattan Only)",
variable=delivery_var,
onvalue="Rush",
offvalue="Standard",
command=get_delivery_type
)
chk_delivery.pack(pady=40)
root.mainloop()You can see the output in the screenshot below.

This method saves me from writing extra “if-else” blocks later in the code to convert 1s and 0s into readable strings.
Handle Multiple Checkbuttons Simultaneously
In professional Python development, you’ll rarely have just one checkbox.
Usually, you’re dealing with a list of options, like selecting multiple US states for a marketing campaign.
I prefer using a dictionary or a list to store my variables so I can loop through them to see which ones are selected.
import tkinter as tk
def process_selection():
selected_regions = []
# I loop through the dictionary to check which variables are True
for region, var in region_vars.items():
if var.get():
selected_regions.append(region)
output_text = "Selected Regions: " + ", ".join(selected_regions) if selected_regions else "No Regions Selected"
result_label.config(text=output_text)
root = tk.Tk()
root.title("US Sales Territory Manager")
root.geometry("500x350")
tk.Label(root, text="Select Target Territories:", font=("Arial", 12, "bold")).pack(pady=10)
regions = ["Northeast", "Southeast", "Midwest", "Southwest", "West"]
region_vars = {}
# Creating multiple checkbuttons dynamically
for region in regions:
var = tk.BooleanVar()
region_vars[region] = var
cb = tk.Checkbutton(root, text=region, variable=var)
cb.pack(anchor="w", padx=50)
btn = tk.Button(root, text="Generate Report", command=process_selection, bg="blue", fg="white")
btn.pack(pady=20)
result_label = tk.Label(root, text="", wraplength=400)
result_label.pack()
root.mainloop()This dynamic approach is how I handle large-scale forms without cluttering my workspace with individual variable names.
Troubleshoot Common Issues
While getting values seems simple, I’ve seen a few recurring bugs in production code.
One common issue is “Variable Garbage Collection.” If you define your IntVar inside a function without making it global or attaching it to an object, Python might delete it.
Always ensure your variables are defined in a scope where they stay alive as long as the window is open.
Another tip I always give my trainees is to use the .set() method to establish a default state.
An uninitialized Checkbutton can sometimes behave unpredictably or show a “half-checked” state on certain operating systems like macOS or Windows 11.
Best Practices for Professional UI
When I design tools for American corporate clients, clarity is king.
Always use clear labels that explain exactly what checking the box does.
If you are using custom onvalue and offvalue, make sure they match the data types expected by your database or API.
I also recommend grouping related checkbuttons within a LabelFrame to give the user a visual cue that the options are connected.
Managing Checkbutton values in Tkinter is a fundamental skill that opens up many possibilities for user input.
By using the right variable type, be it Boolean, Integer, or String, you can make your code much more efficient.
I’ve found that taking the extra minute to set up onvalue strings often saves me hours of debugging later.
I hope this tutorial helps you build better, more responsive Python applications.
You may also like to read:
- Tkinter Get Mouse Position
- How to Get Text from a Tkinter Entry Widget
- Python Tkinter Button Command
- How to Get Text from a Tkinter Label in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.