
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
import kivy from kivy.app 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' )) self.active = CheckBox(active=True) self.add_widget(self.active) self.add_widget(Label(text='3 PM to 4 PM')) self.active = CheckBox(active=False) self.add_widget(self.active) class CheckBoxApp(App): def build(self): return chk_box() CheckBoxApp().run()
Output
Running the above code gives us the following result −
Advertisements