Daniel Daniel - 8 days ago 4
Python Question

Kivy checkboxes don't work in ScrollView

I can't figure out why checkboxes don't work in a

ScrollView
. The following code and .kv file do not allow checkboxes to be clicked unless I remove the
ScrollView
.

from kivy.app import App
from kivy.uix.screenmanager import (ScreenManager, Screen)
from kivy.uix.scrollview import ScrollView


class MainManager(ScreenManager):
pass

class Scrolling(ScrollView):
pass

class LoginScreen(Screen):
pass

class QuestionApp(App):
def build(self):
AppSM = MainManager()
AppSM.add_widget(LoginScreen(name='login'))
return AppSM

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


and .kv file

<LoginScreen>:
Scrolling:
GridLayout:
cols: 1
padding: 15
spacing: 50
size_hint_y: None
height: self.minimum_height
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
<Scrolling>:
do_scroll_x: False
bar_margin: 0
bar_width: 15
bar_color: [.7,.7,.7,.9]
bar_inactive_color: [.7,.7,.7,.9]
scroll_type: ['bars','content']


If I change
<LoginScreen>:
to the following, removing the scrolling, the checkboxes work just fine:

<LoginScreen>:
GridLayout:
cols: 1
padding: 15
spacing: 50
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True

Answer

Change your kv file to this:

BoxLayout:
    size_hint_y: None
    height: 200
    orientation: 'horizontal'
    CheckBox:
        active: False
    CheckBox:
        active: True

then the CheckBoxes work (at least for me). The reason why is most likely because of the explicitly stated height, which I think the GridLayout expects when you set height: self.minimum_height.