Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there builtin way to get a ToggleButton group's current selection?

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 ToggleButtons 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
like image 365
Totem Avatar asked Aug 01 '15 14:08

Totem


1 Answers

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
like image 135
zabeltech Avatar answered Oct 26 '22 02:10

zabeltech