dimanche 3 mai 2020

Check or uncheck checkbox using another checkbox using kivy

I have 2 checkboxes where I need them to work as follows:

If first one gets unchecked (enable project actors) and the second one was already checked (Allow using only..), it will get unchecked also. But when I check the first one, second one will stay unchecked. Alogn that, there is a boolean variable only_def_actors which needs to be set to False if second checkbox is unchecked.

I have tried this, but I am getting `TypeError: 'bool' object is not callable. I don't know which attribute should I change to make it work. Or maybe its easier to do?

In main.kv:

#defined id of checkbox to use in .py
only_def_act: only_def_actors


Label:
    text: "Enable project actors"
CheckBox:
    on_active: root.actors_checkbox_click(self, self.active)
    active: True

Label:
    text: "Allow using only defined actors"
CheckBox:
    id: only_def_actors
    on_active: root.only_def_actors_checkbox_click(self, self.active)

In main.py:

#defined variables
only_def_act = ObjectProperty(None)
actors_status = BooleanProperty(True) #this one is set to be checked by default
only_def_actors = BooleanProperty(False) #this one is set to be unchecked by default

# Callback for the checkbox
def only_def_actors_checkbox_click(self, instance, value):
    if value is True:
        self.only_def_actors = True
        print("T")
    else:
        self.only_def_actors = False
        self.only_def_act.active(False)
        print("F")

# Callback for the checkbox
def actors_checkbox_click(self, instance, value):
    if value is True:
        self.actors_status = True
        print("T")
    else:
        self.actors_status = False
        self.only_def_actors_checkbox_click(instance, False)
        print("F")



Aucun commentaire:

Enregistrer un commentaire