Created
February 3, 2021 09:00
-
-
Save dunossauro/632eedbb8ab6ca1d4438c2015c6582a4 to your computer and use it in GitHub Desktop.
Choice Grid / Radio Options / Toogle Choices for Kivy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.uix.gridlayout import GridLayout | |
from kivy.uix.label import Label | |
from kivy.uix.checkbox import CheckBox | |
from functools import partial | |
class ChoiceGrid(GridLayout): | |
def __init__(self, group='group', **kwags): | |
super().__init__(cols=2, **kwags) | |
self.active = None | |
self._names = None | |
self.group = group | |
@property | |
def names(self): | |
return self._names | |
@names.setter | |
def names(self, names): | |
self._names = names | |
self.config(names, self.group) | |
def checkbox_active(self, checkbox, value, text): | |
if value: | |
self.active = text | |
def config(self, names, group): | |
for name in names: | |
label = Label(text=name) | |
checkbox = CheckBox(group=group) | |
checkbox.bind( | |
active=partial(self.checkbox_active, text=label.text) | |
) | |
self.add_widget(label) | |
self.add_widget(checkbox) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment