Kivy复选框不适用于ScrollView

时间:2016-12-01 17:53:33

标签: python kivy kivy-language

我无法弄清楚为什么复选框无法在ScrollView中运行。以下代码和.kv文件不允许单击复选框,除非我删除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()

和.kv文件

<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']

如果我将<LoginScreen>:更改为以下内容,删除滚动,则复选框工作正常:

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

1 个答案:

答案 0 :(得分:1)

将您的kv文件更改为:

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

然后CheckBox es工作(至少对我而言)。之所以最有可能是因为明确指出了高度,我认为GridLayout在设置height: self.minimum_height时会有所期望。