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
No that is not possible with builtins. But here is how I would do it:
tb = next( (t for t in TB.get_widgets('group') if t.state=='down'), None)
test = tb.text if tb else None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With