将滚动条添加到Kivy中的Boxlayout中 [英] Adding Scrollbar to Boxlayout in Kivy

查看:123
本文介绍了将滚动条添加到Kivy中的Boxlayout中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Kivy中的ScrollBar进行Boxlayout,但无法执行. .kv文件的摘录下面.一旦Boxlayout溢出控件被隐藏并且没有滚动条,我将向Boxlayout动态添加控件.请告知.

I am trying to a Boxlayout with ScrollBar in Kivy, but I am not able to do it. Below excerpt of .kv file. I am dynamically adding controls to Boxlayout once the Boxlayout overflows controls are hidden and there is not Scrollbar. Please advise.

<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()

推荐答案

ScrollView:
        size_hint: (None, None)
        size: (400, 400)
        BoxLayout:
            id: output
            orientation: 'vertical'

BoxLayout没有手动设置的高度,因此它始终精确地填充Scrollview,并且永远不需要滚动条.

The BoxLayout has no manually set height, so it always precisely fills the Scrollview, and never needs a scrollbar.

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

You probably actually want something like the following

ScrollView:
        size_hint: (None, None)
        size: (400, 400)
        GridLayout:
            id: output
            cols: 1
            size_hint_y: None
            height: self.minimum_height

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

These last two lines set the gridlayout height to track the sum of heights of its children. You could also set the height to anything else.

这篇关于将滚动条添加到Kivy中的Boxlayout中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆