Kivy Scroll View выпуск - PullRequest
       5

Kivy Scroll View выпуск

0 голосов
/ 09 марта 2020

Я хочу добавить представление прокрутки к radiobuttons, используя kv язык.

Мой код:

main.py

from kivymd.app import MDApp
from kivy.lang import Builder

class MyKivyApp(MDApp):
    def build(self):
        self.root = Builder.load_file("main.kv")
        return self.root

if __name__ == "__main__":
    MyKivyApp().run()

main.kv

<RadioButton@CheckBox>:
    group: "radioButtons"
    size_hint_y: None
    height: 40

<TestLabel@Label>:
    text: "Test"
    color: (1, 0, 0, 1)

ScrollView:
    size_hint: (1, 1)
    pos_hint: {"x": 0.45}

    GridLayout:
        cols: 1
        padding: 10
        spacing: 15
        size_hint_y: None
        size_hint_x: None
        width: dp(100)
        height: self.minimum_height

        TestLabel:
            text: "Main Label"

        TextInput:
            id: oneTxt
            pos_hint: {"top": 0.1}
            size_hint: (1, 1)

        Button:
            id: btn1
            text: "Button 1"
            pos_hint: {"top": 0.4}

        GridLayout:
            cols: 2
            padding: 0
            spacing: 0
            size_hint_y: None
            size_hint_x: None
            height: self.minimum_height

            RadioButton:
            TestLabel:
                text: "Test1"

            RadioButton:
            TestLabel:
                text: "Test2"

            RadioButton:
            TestLabel:
                text: "Test3"

            RadioButton:
            TestLabel:
                text: "Test4"

            RadioButton:
            TestLabel:
                text: "Test5"

            RadioButton:
            TestLabel:
                text: "Test6"

            RadioButton:
            TestLabel:
                text: "Test7"

            RadioButton:
            TestLabel:
                text: "Test8"

            RadioButton:
            TestLabel:
                text: "Test9"

            RadioButton:
            TestLabel:
                text: "Test10"

            RadioButton:
            TestLabel:
                text: "Test11"

            RadioButton:
            TestLabel:
                text: "Test12"

            RadioButton:
            TestLabel:
                text: "Test13"

            RadioButton:
            TestLabel:
                text: "Test14"

            RadioButton:
            TestLabel:
                text: "Test15"

            RadioButton:
            TestLabel:
                text: "Test16"

            RadioButton:
            TestLabel:
                text: "Test17"

            RadioButton:
            TestLabel:
                text: "Test18"

            RadioButton:
            TestLabel:
                text: "Test19"

            RadioButton:
            TestLabel:
                text: "Test20"

            RadioButton:
            TestLabel:
                text: "Test21"

            RadioButton:
            TestLabel:
                text: "Test22"

            RadioButton:
            TestLabel:
                text: "Test23"

            RadioButton:
            TestLabel:
                text: "Test24"

            RadioButton:
            TestLabel:
                text: "Test25"

            RadioButton:
            TestLabel:
                text: "Test26"

            RadioButton:
            TestLabel:
                text: "Test27"

            RadioButton:
            TestLabel:
                text: "Test28"

            RadioButton:
            TestLabel:
                text: "Test29"

            RadioButton:
            TestLabel:
                text: "Test30"

            RadioButton:
            TestLabel:
                text: "Test31"

            RadioButton:
            TestLabel:
                text: "Test32"

        TestLabel:
            text: "End Label"

        Button:
            id: btn2
            text: "Button 2"
            pos_hint: {"top": 0.8}

Прокрутка работает, но другие виджеты маленькие и перекрывают друг друга. Проверьте изображение ниже:

enter image description here

Как это исправить? Спасибо.

1 Ответ

1 голос
/ 09 марта 2020

Когда вы устанавливаете height для GridLayout на self.minimum_height, вам нужно указать height для каждого ребенка. Например, первые три дочерних элемента внешнего GridLayout могут быть:

    TestLabel:
        text: "Main Label"
        size_hint: (None, None)
        size: self.texture_size[0] + 10, self.texture_size[1] + 10

    TextInput:
        id: oneTxt
        size_hint: (1, None)
        height: 40

    Button:
        id: btn1
        text: "Button 1"
        size_hint: (None, None)
        size: self.texture_size[0] + 10, self.texture_size[1] + 10

Аналогично, последние два могут быть:

    TestLabel:
        text: "End Label"
        size_hint: (None, None)
        size: self.texture_size[0] + 10, self.texture_size[1] + 10

    Button:
        id: btn2
        text: "Button 2"
        size_hint: (None, None)
        padding: 10,10
        size: self.texture_size
...