在Kivy中将滚动条添加到Boxlayout

skv*_*ree 1 python kivy

我正在Kivy尝试使用ScrollBar的Boxlayout,但我无法做到.下面是.kv文件的摘录.一旦Boxlayout溢出控件被隐藏且没有Scrollbar,我就会动态地向Boxlayout添加控件.请指教.

<ProcessorUI>: #GridLayout
    cols: 1
    rows: 3
    Label:
        text: 'Output'
        size_hint_x: None
        width: 100
        size_hint_y: None
        height: 20
    ScrollView:
        size_hint: (None, None)
        size: (400, 400)
        BoxLayout:
            id: output
            orientation: 'vertical'
    GridLayout
        cols: 2
        TextInput:
            id: input
            multiline: True
            size_hint_y: None
            height: 40
        Button:
            id: btn_process
            text: 'Process'
            size_hint_x: None
            width: 100
            size_hint_y: None
            height: 40
            on_press: root.on_event()
Run Code Online (Sandbox Code Playgroud)

inc*_*ent 7

ScrollView:
        size_hint: (None, None)
        size: (400, 400)
        BoxLayout:
            id: output
            orientation: 'vertical'
Run Code Online (Sandbox Code Playgroud)

BoxLayout没有手动设置的高度,所以它总是精确地填充Scrollview,并且永远不需要滚动条.

您可能实际上想要以下内容

ScrollView:
        size_hint: (None, None)
        size: (400, 400)
        GridLayout:
            id: output
            cols: 1
            size_hint_y: None
            height: self.minimum_height
Run Code Online (Sandbox Code Playgroud)

最后两行设置gridlayout高度以跟踪其子项的高度总和.您还可以将高度设置为其他任何值.