Guilty
Guilty

Reputation: 492

How to have ToggleButtons stop being pressed "down" only when another toggle is Pressed

I have a set of Python Kivy ToggleButtons which are all apart of the same group, e.g.

self.add_widget(CustomToggleButton("0", "group1"))
self.add_widget(CustomToggleButton("1", "group1"))
self.add_widget(CustomToggleButton("2", "group1"))
self.add_widget(CustomToggleButton("3", "group1"))
self.add_widget(CustomToggleButton("4", "group1"))
self.add_widget(CustomToggleButton("5", "group1"))

Because they are part of the same group only one can be pressed at a time. This is the desired behavior, however I want to also disable the ability to "re-click" on a pressed down toggle button to turn it off. i.e. the user will only be able to turn the toggle button off by turning another one on.

Upvotes: 0

Views: 236

Answers (1)

Darnell Baird
Darnell Baird

Reputation: 243

Good day. Bind to each button on the on_release event, the following function.

#python code
def staydown_callback(self, btn, *args):
    setattr(btn, 'state', 'down')



#kvlang
on_release: setattr(self, 'state', 'down')    #self is the button

Upvotes: 2

Related Questions