Python Checkbox widget in Kivy?

Kivy is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to use the GridLayout and CheckBox.

After importing the relevant modules, we create a grid layout with 2 columns. One to hold the label and another to hold the checkboxes.


import kivy
from import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.checkbox import CheckBox
from kivy.uix.gridlayout import GridLayout

# Container class for the app's widgets
class chk_box(GridLayout):

   def __init__(self, **kwargs):
      super(chk_box, self).__init__(**kwargs)

      # Grid layout for 2 columns
      self.cols = 2

      # Add checkbox, widget and labels
      self.add_widget(Label(text='10 AM to 11 AM' )) = CheckBox(active=True)

      self.add_widget(Label(text='3 PM to 4 PM')) = CheckBox(active=False)

class CheckBoxApp(App):
   def build(self):
      return chk_box()



Running the above code gives us the following result −