TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python Tkinter Checkbutton

Python Tkinter Checkbutton with python tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, basics, data types, operators, etc.

<< Back to PYTHON

Python Tkinter Checkbutton

The Checkbutton is used to track the user's choices provided to the application. In other words, we can say that Checkbutton is used to implement the on/off selections.

The Checkbutton can contain the text or images. The Checkbutton is mostly used to provide many choices to the user among which, the user needs to choose the one. It generally implements many of many selections.

The syntax to use the checkbutton is given below.

Syntax

w = checkbutton(master, options)

A list of possible options is given below.

SN Option Description
1 activebackground It represents the background color when the checkbutton is under the cursor.
2 activeforeground It represents the foreground color of the checkbutton when the checkbutton is under the cursor.
3 bg The background color of the button.
4 bitmap It displays an image (monochrome) on the button.
5 bd The size of the border around the corner.
6 command It is associated with a function to be called when the state of the checkbutton is changed.
7 cursor The mouse pointer will be changed to the cursor name when it is over the checkbutton.
8 disableforeground It is the color which is used to represent the text of a disabled checkbutton.
9 font It represents the font of the checkbutton.
10 fg The foreground color (text color) of the checkbutton.
11 height It represents the height of the checkbutton (number of lines). The default height is 1.
12 highlightcolor The color of the focus highlight when the checkbutton is under focus.
13 image The image used to represent the checkbutton.
14 justify This specifies the justification of the text if the text contains multiple lines.
15 offvalue The associated control variable is set to 0 by default if the button is unchecked. We can change the state of an unchecked variable to some other one.
16 onvalue The associated control variable is set to 1 by default if the button is checked. We can change the state of the checked variable to some other one.
17 padx The horizontal padding of the checkbutton
18 pady The vertical padding of the checkbutton.
19 relief The type of the border of the checkbutton. By default, it is set to FLAT.
20 selectcolor The color of the checkbutton when it is set. By default, it is red.
21 selectimage The image is shown on the checkbutton when it is set.
22 state It represents the state of the checkbutton. By default, it is set to normal. We can change it to DISABLED to make the checkbutton unresponsive. The state of the checkbutton is ACTIVE when it is under focus.
24 underline It represents the index of the character in the text which is to be underlined. The indexing starts with zero in the text.
25 variable It represents the associated variable that tracks the state of the checkbutton.
26 width It represents the width of the checkbutton. It is represented in the number of characters that are represented in the form of texts.
27 wraplength If this option is set to an integer number, the text will be broken into the number of pieces.

Methods

The methods that can be called with the Checkbuttons are described in the following table.

SN Method Description
1 deselect() It is called to turn off the checkbutton.
2 flash() The checkbutton is flashed between the active and normal colors.
3 invoke() This will invoke the method associated with the checkbutton.
4 select() It is called to turn on the checkbutton.
5 toggle() It is used to toggle between the different Checkbuttons.

Example

from tkinter import * 

top = Tk()

top.geometry("200x200")

checkvar1 = IntVar()

checkvar2 = IntVar()

checkvar3 = IntVar()

chkbtn1 = Checkbutton(top, text = "C", variable = checkvar1, onvalue = 1, offvalue = 0, height = 2, width = 10)

chkbtn2 = Checkbutton(top, text = "C++", variable = checkvar2, onvalue = 1, offvalue = 0, height = 2, width = 10)

chkbtn3 = Checkbutton(top, text = "Java", variable = checkvar3, onvalue = 1, offvalue = 0, height = 2, width = 10)

chkbtn1.pack()

chkbtn2.pack()

chkbtn3.pack()

top.mainloop()

Output:

Python Tkinter Checkbutton



Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf