简体   繁体   中英

Checkbox appears and disappears after multiple clicks on one checkbox

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty
from kivy.lang import Builder

Builder.load_string('''
<MyWidget>:
    CheckBox:
        group: "Zone "
        active: root.odrzuc
        on_state: self.active
    CheckBox:
        group: "Zone "
        active: root.decyduj
        on_state: self.active

''')

class MyWidget(BoxLayout):
    odrzuc = BooleanProperty(False)
    decyduj = BooleanProperty(True)


class MyApp(App):
    def build(self):
        return MyWidget()

if __name__ == '__main__':
    MyApp().run()

I want to click on one of the checkbox and it will turn on and the other turn off. I can block them using 'on_state: self.active', but I do not know how to unblock one, when the second one is blocked and vice versa.

You should give them a group:

group: 'my-group'

and set this:

allow_no_selection: False

Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM