Python Tkinter CheckButton

In this tutorial, we will learn about Python Tkinter CheckButton. The Python Tkinter CheckButtons are used to show options to the user to choose. We can add any number of CheckButtons according to the requirement of the application. The important thing to note about checkbox is the user can choose multiple checkboxes from given options. If you want to user choose the only single option you can use the radio button.

Syntax to add Python Tkinter CheckButton:

w = Checkbutton ( master, option, ... )
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program:

from tkinter import *

mainWindow = Tk()  

#setting size of main window 
mainWindow.geometry("200x200")

cb1 = Checkbutton(mainWindow, text = "Python", \
                 onvalue = 1, offvalue = 0, height=5, \
                 width = 20)
cb2 = Checkbutton(mainWindow, text = "Java", \
                 onvalue = 1, offvalue = 0, height=5, \
                 width = 20)
cb1.pack()
cb2.pack()
mainWindow.mainloop()

Output:

Python Tkinter CheckButton

Various possible options in Python Tkinter CheckButton:

OptionDescription
activebackgroundThis option helps us to set background color of widget when on cursor hover.
activeforegroundThis option helps us to set foreground color of widget when on cursor hover.
bgThis option helps us to set normal background color of label and indicator.
bdThis option helps us to set the border size around indicator.
fgThis option helps us to set normal foreground colour of widget.
heightThis option helps us to set height of widget.
commandThis option helps us to mention a function to every time when checkbutton will change its state.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
fontThis option helps us to set the style of font.
justifyThis helps us to automatically organize the text in multiple lines.
padxThis option helps us to set space left and right between text and checkbox.
padyThis option helps us to set space above and below.
reliefThis helps us to set the style of the border by which is default Flat.
widthThis helps us to set the width of the widget.

Python Tkinter CheckButton Methods:

After learning about various available options in Python Tkinter CheckButton. Its time to check out some available methods for Python Tkinter CheckButton widget.

METHODDESCRIPTION
deselect()This method called to deselect the CheckButton.
flash()This method is used to flash CheckButton between normal and active state.
invoke()This method helps us to invoke the associated method with CheckButton.
select()This method is used to select the CheckButton.
toggle()This method helps us to toggle between different CheckButton.
Spread the love