I was just browsing through the source in search of a way to do this but didn't see any. I want to be sure though, as I may have missed something. Is there a builtin way, like a method? When I have some ToggleButton
s that are in a group together, I want to be able to get the value(text value I suppose), of the currently selected(state == 'down'
) button. I know I can roll my own way to do this without much hassle, but it seems strange that it wouldn't already exist.
After inspection of the docs and the source, I find this to be the easiest way so far:
from kivy.uix.togglebutton import ToggleButton as TB
current = [t for t in TB.get_widgets('group') if t.state=='down'][0]
value = current.text
While this isn't very long or hard to do, it would be nice to be able to do something like:
WARNING: Fictional Code
value = TB.get_widgets('group').selected
allow_no_selection
is set, there may be a group without a button in down state. – Morrissette