Python Tkinter CheckbuttonPython Tkinter Checkbutton

Python Tkinter Checkbutton – A Complete Guide

Python Tkinter Checkbutton – A Complete Guide

Interested in above project ,Click Below
WhatsApp
Telegram
LinkedIn

Python Tkinter Checkbutton

In GUI applications, user input plays a crucial role, and Tkinter, the standard GUI toolkit in Python, offers various widgets to handle such interactions. One such essential widget is the Checkbutton. The Checkbutton allows users to make multiple selections from a given set of choices. It provides an intuitive on/off switch, making it useful for forms, settings, and preference-based applications.

Complete Python Course with Advance topics:-Click here

What is a Tkinter Checkbutton?

A Checkbutton is a type of button that allows users to select multiple options from a list. It acts as a toggle switch where users can check or uncheck a particular choice. The Checkbutton can display both text and images, making it versatile for different UI needs.

Syntax of Checkbutton

w = Checkbutton(master, options)

Here, master is the parent widget (like a Tkinter window or frame), and options are various attributes to customize the Checkbutton.

Tkinter Checkbutton Options

The table below describes the various configuration options available for the Checkbutton widget:

SNOptionDescription
1activebackgroundBackground color when the Checkbutton is hovered.
2activeforegroundForeground (text) color when hovered.
3bgBackground color of the Checkbutton.
4bitmapDisplays a monochrome image on the Checkbutton.
5bdSets the border size of the Checkbutton.
6commandAssociates a function to be executed when the Checkbutton state changes.
7cursorChanges the mouse cursor when hovering over the Checkbutton.
8disableforegroundColor of the text when the Checkbutton is disabled.
9fontSets the font style of the Checkbutton.
10fgForeground (text) color of the Checkbutton.
11heightSpecifies the height of the Checkbutton. Default is 1.
12highlightcolorColor of the focus highlight when the Checkbutton is selected.
13imageDisplays an image on the Checkbutton.
14justifyAligns text when multiline text is used.
15offvalueValue assigned when the Checkbutton is unchecked (default: 0).
16onvalueValue assigned when the Checkbutton is checked (default: 1).
17padxHorizontal padding inside the Checkbutton.
18padyVertical padding inside the Checkbutton.
19reliefBorder style of the Checkbutton (default: FLAT).
20selectcolorColor of the Checkbutton when selected (default: red).
21selectimageDisplays a different image when the Checkbutton is selected.
22stateState of the Checkbutton (NORMAL, DISABLED, ACTIVE).
23underlineUnderlines a specific character in the Checkbutton label.
24variableLinks the Checkbutton to a Tkinter variable.
25widthSpecifies the width of the Checkbutton in characters.
26wraplengthWraps text into multiple lines at a specified width.

Tkinter Checkbutton Methods

Below are the common methods available for the Checkbutton widget:

See also  SQL FULL JOIN - A Complete Guide

SNMethodDescription
1deselect()Unchecks the Checkbutton.
2flash()Flashes between active and normal colors.
3invoke()Calls the function associated with the Checkbutton.
4select()Checks the Checkbutton.
5toggle()Toggles the Checkbutton state (checked/unchecked).

Example: Creating Checkbuttons in Tkinter

Here’s a simple example demonstrating how to create multiple Checkbuttons in a Tkinter window:

from tkinter import *

# Create main window
top = Tk()
top.geometry("250x200")

title_label = Label(top, text="Select Your Preferred Languages:", font=("Arial", 10, "bold"))
title_label.pack()

# Define Tkinter variables
checkvar1 = IntVar()
checkvar2 = IntVar()
checkvar3 = IntVar()

# Creating Checkbuttons
chkbtn1 = Checkbutton(top, text="Python", variable=checkvar1, onvalue=1, offvalue=0, height=2, width=10)
chkbtn2 = Checkbutton(top, text="Java", variable=checkvar2, onvalue=1, offvalue=0, height=2, width=10)
chkbtn3 = Checkbutton(top, text="C++", variable=checkvar3, onvalue=1, offvalue=0, height=2, width=10)

chkbtn1.pack()
chkbtn2.pack()
chkbtn3.pack()

# Run main event loop
top.mainloop()

Output:

This will create a simple GUI with three checkboxes labeled Python, Java, and C++, allowing users to select multiple options.

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

The Checkbutton widget in Tkinter is a powerful component for handling multiple-choice selections in Python GUI applications. It supports various configurations and methods to customize user interactions effectively. Whether used in forms, settings, or user preferences, the Checkbutton provides a seamless experience for capturing user input.

For more Python GUI tutorials and advanced Tkinter projects, stay tuned to UpdateGadh!


python tkinter checkbutton example
python tkinter checkbutton get value
python tkinter checkbutton tutorial
tkinter checkbutton set value
tkinter checkbutton command
tkinter checkbutton state
tkinter checkbutton select
tkinter checkbutton default value
python tkinter checkbutton
python tkinter checkbutton default checked
python tkinter checkbutton get value
python tkinter checkbutton example
python tkinter checkbutton command
python tkinter checkbutton size
python tkinter checkbutton disable

See also  SQL WHERE Clause in SQL DML Statements

    🎓 Need Complete Final Year Project?

    Get Source Code + Report + PPT + Viva Questions (Instant Access)

    🛒 Visit UpdateGadh Store →
    💬 Chat Now