mercredi 6 mai 2020

Disable one checkbox by another in Kivy

I need to make checkbox B disabled by selection of checkbox A in Kivy app.

I tried to use on_selection, but it returns the following error:

File "C:\ProgramData\Miniconda3\Lib\site-packages\kivy\lang\builder.py", line 734, in _apply_rule
  '{}: {}'.format(e.__class__.__name__, e), cause=tb)

kivy.lang.builder.BuilderException: Parser: File "C:\GUI Projects\unicort\unicort.kv", line 427:
...
425: id: accept_wordlists_checkbox
426: on_selection:
>> 427: root.ids.bigr_checkbox.disabled: True
428:
429:
...
AttributeError: selection

It seems that checkbox can not call anything, it's only for conditions.

Technically, I could substitute checkbox A with a button and use it to call a function (because on_release works well) that would disable checkbox B, but I still need the checkbox A for a condition (for another function).

Here is my code in Kivy language:

                BoxLayout:

                    BoxLayout:
                        height: 50

                        Label: 

                            text: '[b]Accept wordlist[/b]'
                            markup: True
                            font_size: 16
                            size_hint_y: None
                            height: 50

                        CheckBox: # checkbox A

                            text: 'Yes'
                            id: accept_wordlists_checkbox
                            on_selection:
                                root.ids.bigr_checkbox.disabled: True


                    Label:

                        id: indexation_type_label
                        text: 'Indexation of all words'

                    Label: 

                        text: '[b]Indexation of[/b]'
                        markup: True
                        font_size: 16
                        size_hint_y: None
                        height: 50

                    GridLayout:

                        cols: 2
                        size_hint_y: None
                        height: 75

                        BoxLayout:

                            orientation: 'vertical'

                            Label:

                                text: 'Single words'
                                font_size: 14

                            CheckBox:
                                size_hint_y: None
                                height: '48dp'
                                group: 'g4'
                                id: single_checkbox

                        BoxLayout:

                            orientation: 'vertical'

                            Label:

                                text: 'Bigrams'
                                font_size: 14

                            CheckBox: # checkbox B

                                size_hint_y: None
                                height: '48dp'
                                group: 'g4'
                                id: bigr_checkbox



Aucun commentaire:

Enregistrer un commentaire