Kivy Tutorials
About Lesson

In this Kivy Tutorial we are going to learn about Kivy ToggleButton, according to Kivy Documentation the ToggleButton widget acts like a checkbox. When you touch or click it, the state toggles between ‘normal’ and ‘down’ (as opposed to a Button that is only ‘down’ as long as it is pressed). toggle buttons can also be grouped to make radio buttons – only one button in a group can be in a ‘down’ state. the group name can be a string or any other hashable Python object.

 

 

We are going to create two files the first one is our Python file and the second file is our Kivy file, so first let’s create our Python file, and we want to add the following codes in that file.

 

In the above code first we have created MyToggleButton class, this class extends from GridLayout, because we want to add our kivy toggle button in the GridLayout, and we are not going to do anything in this class, it is just an empty class. you need return this class in your main class.

 

 

 

 This is our .kv file, and i have name the file togglewindow.kv, make sure that this name should be similar to the main  class name, in my case it is ToggleWindow class. in the file we need to define some rules for the Kivy ToggleButton, you need to specify the number of columns for the GridLayout, also we have added a RelativeLayout and in the RelativeLayout we have added our two togglebutton.

 

 

 

Run the complete code and this is the result.

Kivy Tutorial - Kivy ToggleButton
Kivy Tutorial – Kivy ToggleButton