首页 > 解决方案 > 如何在 Kivy 的 RecycleView 中显示大滚动条

问题描述

我在 Python 中的 Kivy 中编写了以下代码。

它是一个只有五个可以滚动的按钮的 GUI。

我在 Anacond 环境中运行以下命令。

#-*- coding: utf-8 -*-

from kivy.lang import Builder
Builder.load_string("""
<TextWidget>:
    BoxLayout:
        size: root.size
        orientation: 'vertical'

        RecycleView:
            size_hint: 1.0,1.0

            BoxLayout:
                orientation: 'vertical'
                size_hint_y: 5

                Button:
                    halign: 'center'
                    valign: 'center'
                    text: 'TEST1'

                Button:
                    halign: 'center'
                    valign: 'center'
                    text: 'TEST2'

                Button:
                    halign: 'center'
                    valign: 'center'
                    text: 'TEST3'

                Button:
                    halign: 'center'
                    valign: 'center'
                    text: 'TEST4'

                Button:
                    halign: 'center'
                    valign: 'center'
                    text: 'TEST5'
""")

from kivy.app import App
from kivy.uix.widget import Widget

from kivy.properties import StringProperty 

class TextWidget(Widget):
    text = StringProperty()

    def __init__(self, **kwargs):
        super(TextWidget, self).__init__(**kwargs)

class TestApp(App):
    def __init__(self, **kwargs):
        super(TestApp, self).__init__(**kwargs)
        self.title = 'test'

    def build(self):
        return TextWidget()

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

出现滚动条,但太小而无法触摸。

在此处输入图像描述

所以我必须用鼠标中键滚动。

有没有办法显示大滚动条?

标签: pythonkivy

解决方案


您可以使用以下bar_width属性:

        RecycleView:
            size_hint: 1.0,1.0
            bar_width: dp(10)
            scroll_type: ["bars", "content"]

推荐阅读