Using Checkbox Widget In Python GUI Application

Introduction

 
In this blog, I am going to create a checkbox widget in Python GUI application. It will display the checkbox's status on the application screen.
 
Software requirement
 
Python 3.5 and IDLE (Python 3.5)
 
Programming code
  1. #Checkbox Using Application  
  2. import tkinter as tk  
  3. from tkinter import ttk  
  4. win = tk.Tk()  
  5. win.title("Python GUI App")  
  6. #Label Creation  
  7. ttk.Label(win, text="Checkbox status :").grid(column=0,row=0)  
  8. #Create three Checkbox  
  9. #Disabled Checkbox  
  10. chVarDis=tk.IntVar()  
  11. check1=tk.Checkbutton(win, text="Disabled", variable=chVarDis, state='disabled')  
  12. check1.select()  
  13. check1.grid(column=0,row=4, sticky=tk.W)  
  14. #Deselected Checkbox  
  15. chVarUn=tk.IntVar()  
  16. check2=tk.Checkbutton(win, text="UnChecked", variable=chVarUn)  
  17. check2.deselect()  
  18. check2.grid(column=1,row=4, sticky=tk.W)  
  19. #Selected Checkbox  
  20. chVarEn=tk.IntVar()  
  21. check3=tk.Checkbutton(win, text="Enabled", variable=chVarEn)  
  22. check3.select()  
  23. check3.grid(column=2,row=4, sticky=tk.W)  
  24. #Calling Main()  
  25. win.mainloop()  
About the code
  • First, import the tkinter module.
  • Next, assign a class and variables and give application title.
  • Next, create three checkboxes and its status.
  • Finally, I have started the Windows event loop by calling the main loop method, then executed the code.
Output