The Wayback Machine - https://web.archive.org/web/20240118180756/https://www.geeksforgeeks.org/python-tkinter-ttk-checkbutton-and-comparison-with-simple-checkbutton/
Open In App
Related Articles

Python | Tkinter ttk.Checkbutton and comparison with simple Checkbutton

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Tkinter is a GUI (Graphical User Interface) module which comes along with the Python itself. This module is widely used to create GUI applications. tkinter.ttk is used to create the GUI applications with the effects of modern graphics which cannot be achieved using only tkinter. Checkbutton is used to select multiple options. Checkbuttons can be created using following snippet.

Note
Tkinter.Checkbutton: This widget was used to create a checkbutton, but it has been replaced by 
the tkinter.Checkbutton() widget, which provides more options and better support for different 
checkbutton styles.
chkbtn = ttk.Checkbutton(master, option=value, ...)

Code #1: 

Python3




# importing tkinter.ttk
from tkinter import *
from tkinter.ttk import *
 
# creating root
root = Tk()
 
# label text
Label(root, text ='Select Programming language of your choice').place(x = 20, y = 0)
 
# check buttons
java = Checkbutton(root, text ='Java',
                   takefocus = 0).place(x = 40, y = 30)
 
cpp = Checkbutton(root, text ='C++',
                  takefocus = 0).place(x = 40, y = 50)
 
python = Checkbutton(root, text ='Python',
                     takefocus = 0).place(x = 40, y = 70)
 
c = Checkbutton(root, text ='C',
                takefocus = 0).place(x = 40, y = 90)
 
root.mainloop()


Output:

Image  

Code #2: Difference between simple Checkbutton and ttk.Checkbutton 

Python3




# importing tkinter and ttk
from tkinter import *
from tkinter import ttk
 
# root
root = Tk()
 
# This will depict the features of Simple Checkbutton
Label(root, text ='Simple Checkbutton').place(x = 10, y = 10)
chkbtn1 = Checkbutton(root, text ='Checkbutton1',
             takefocus = 0).place(x = 10, y = 40)
chkbtn2 = Checkbutton(root, text ='Checkbutton2',
             takefocus = 0).place(x = 10, y = 60)
 
 
# This will depict the features of ttk.Checkbutton
Label(root, text ='ttk.Checkbutton').place(x = 140, y = 10)
chkbtn1 = ttk.Checkbutton(root, text ='Checkbutton1',
                takefocus = 0).place(x = 140, y = 40)
chkbtn2 = ttk.Checkbutton(root, text ='Checkbutton2',
                takefocus = 0).place(x = 140, y = 60)
 
root.mainloop()


Output: Image Notice the difference in the appearance of both the Checkbuttons which is all due to the modern graphics. In the above Code when mouse is being hovered over the ttk.Checkbutton you may see a blue color effect (effect may change from os from os). When we hover mouse over Simple Checkbutton you may not experience any such kind of effects.


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 19 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials