Introduction

In this article, I will explain how to use a checkbox in tkinter in Python.
Definition
The Checkbutton keyword is used to display a number of options to a user as toggle buttons. The customer selects one or more options by clicking the button corresponding to each option.
Syntax
  1. w = Checkbutton ( a, option) #C is capital letter.
Parameters
a − This represents the parent window of the computer.
option − The list of most used options for this widget.

Options & Descriptions

Program
  1. from tkinter import *
  2. import tkinter.messagebox
  3. a= Tk()
  4. a.geometry("400x400")
  5. def music():
  6. tkinter.messagebox.showinfo(title="music",message="you select music")
  7. def video():
  8. tkinter.messagebox.showinfo(title="video",message="you select video")
  9. def photo():
  10. tkinter.messagebox.showinfo(title="photo",message="you select photo")
  11. CheckVar1 = IntVar()
  12. CheckVar2 = IntVar()
  13. CheckVar3 = IntVar()
  14. C1 = Checkbutton(a, text = "Music",activebackground="black" , activeforeground="white"\
  15. ,bg="green",bd=10,variable = CheckVar1,\
  16. onvalue = 1, offvalue = 0,command = music).pack()
  17. Label(a, text="").pack()#space
  18. C2 = Checkbutton(a, text = "video",activebackground="black" ,activeforeground="white"\
  19. ,bg="green",bd=10,variable = CheckVar2\
  20. ,onvalue = 1, offvalue = 0,command = video).pack()
  21. Label(a, text="").pack()#space
  22. C3 = Checkbutton(a, text = "photo",activebackground="black" , activeforeground="white"\
  23. ,bg="green",bd=10,variable = CheckVar3,\
  24. onvalue = 1, offvalue = 0,command = photo).pack()
  25. a.mainloop()
Output
How To Add a Checkbox In The Tkinter In Python
Program
  1. from tkinter import *
  2. import tkinter.messagebox
  3. a= Tk()
  4. a.geometry("400x400")
  5. def music():
  6. tkinter.messagebox.showinfo(title="music",message="you select music")
  7. C1 = Checkbutton(a, text ="music",fg="red",bg="green",font="Castellar",height=5,width=5,\
  8. relief="solid",command = music)
  9. C1.pack()
  10. a.mainloop()
Output
How To Add a Checkbox In The Tkinter In Python
Program
  1. from tkinter import *
  2. import tkinter.messagebox
  3. a= Tk()
  4. a.geometry("400x400")
  5. def music():
  6. tkinter.messagebox.showinfo(title="music",message="you select music")
  7. C1 = Checkbutton(a, text ="music",state=DISABLED,justify=RIGHT,padx=10,pady=10\
  8. ,relief="solid",command = music)
  9. C1.pack()
  10. a.mainloop()
Output
How To Add a Checkbox In The Tkinter In Python

Conclusion

In this article, we have seen how to use a checkbox in tkinter in Python. I hope this article was useful to you. Thanks for reading!