Iterate over buttons in GridLayout

684 views
Skip to first unread message

VDK

unread,
Jun 24, 2015, 1:56:14 PM6/24/15
to kivy-...@googlegroups.com
Hi,

I have a GridLayout with multiple buttons. When one of those buttons is clicked, the remaining buttons have to be disabled. I wonder how I can get access to these buttons to disable them. I tried with root.children but that only gives me the the outer BoxLayout, the GridLayout is nested under this BoxLayout. Any help is appreciated.

Thanks,

Peter

Arlo

unread,
Jun 24, 2015, 2:50:02 PM6/24/15
to kivy-...@googlegroups.com
Give your widgets ids.
In Python, access them from the root widget with self.ids.my_widget_id
Or bind them to a Kivy property.

See:
http://kivy.org/docs/guide/lang.html#referencing-widgets

VDK

unread,
Jun 25, 2015, 1:48:03 PM6/25/15
to kivy-...@googlegroups.com
Thanks a lot, I was very close to this topic in the documentation. I read the paragraph about dynamic classes, because I also needed that, but missed the preceding one about the references to widgets.

Peter

Garrett Armstrong

unread,
Jun 26, 2015, 1:20:58 PM6/26/15
to kivy-...@googlegroups.com
Look into grouping buttons.  You can group some buttons so that acting on one will affect the others (i.e., disable, lock).  Another way would be to use the walk function to loop through all the widgets until you find the ones you want to act upon.
Reply all
Reply to author
Forward
0 new messages