Kivy Crash Course – How to Create CheckBox

This is our fifth article in Kivy Crash Course, in this article we are going to learn How to Create CheckBox. CheckBox is a specific two-state button that can be either checked or unchecked. If the CheckBox is in a Group, it becomes a Radio button. As with the ToggleButton, only one Radio button at a time can be selected when the CheckBox.group is set.

 

 

 

Also you can watch the video for this article

 

 

 

Kivy Crash Course Articles

1: Kivy Crash Course Introduction & Installation

2: Introduction to Kv Design Language 

3: Kivy Button with Callbacks

4: Kivy Layout Management 

 

 

 

 

So there are two ways that you can create checkbox in kivy, the first way is that you can create checkbox using the kivy.uix.checkbox module, and the second way is using the kivy design language, so first let’s just do the first way. also iam going to show you how to create callbacks for the kivy checkbox.

 

 

So now this is the code for creating of checkbox in kivy.

 

 

 

So in the above code you can see that we have created a class that extends from GridLayout, and we created our checkboxes and labels in that class, also you can see that i have binded the event with the checkbox like this.

 

 

 

 

And this is my method that i have binded with the checkbox.

 

 

 

This method returns the window content. in this case  our CheckBoxClass class .

 

 

 

 

 

So now if you run the code this will be the result.

Kivy CheckBox
Kivy CheckBox

 

 

 

 

So now let’s create our checkbox  using kivy design language, first of all this is our python code.

 

So you can see at the top i have created a new class, that class extends from GridLayout class , and also you can see that i have added callback in this class, because i want to use that in my kivy file.

 

 

And this is our kivy file, make sure that your kivy file name should be checkboxex.kv, because our main class is CheckBoxEx.

 

So in the kivy file first of all we have added the kivy version, after that we are going to write the class that we want to define rules, in our case it is MyGridLayout and we add our checkbox and labels in our kivy file, also pay attention in the indentation of  code in your kivy file.

 

 

And this is the code that we have binded with the kivy file checkbox.

 

 

 

 

So run the code this will be the result

Kivy Crash Course - How to Create CheckBox
Kivy Crash Course – How to Create CheckBox

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

2 thoughts on “Kivy Crash Course – How to Create CheckBox”

  1. while doing python example practice TK practice programs are working, output is getting but PyQt5 practice programs are not working output is not get, mistakes are showing, what has to do. Thanking You, Prasad

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×