Kivy 元素定位

问题描述 投票:0回答:1

我不明白如何使blk全屏并且项目从上到下而不是从下排序

Here is what the program looks like with the following code

This is what I need

items.py

from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.core.text import LabelBase

Window.size = (430, 930)

class ItemsScreen(BoxLayout):
    pass

class ItemsApp(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        return ItemsScreen()

if __name__ == "__main__":
    LabelBase.register(name="Press Start 2P",
                    fn_regular='./font/PressStart2P-Regular.ttf')
    ItemsApp().run()

项目.kv

<ItemsScreen@Screen>:
    BoxLayout:
        padding: 40
        orientation: 'vertical'
        MDLabel:
            font_name: "Press Start 2P"
            text: 'айтеми'
        BoxLayout:
            BoxLayout:
                spacing: 30
                orientation: 'vertical'
                size_hint: 0.3, 1
                ItemType1:
                ItemType1:
                ItemType1:

            BoxLayout:
                spacing: 30
                orientation: 'vertical'
                size_hint: 0.3, 1
                ItemType2:
                ItemType2:

            BoxLayout:
                spacing: 30
                orientation: 'vertical'
                size_hint: 0.3, 1
                ItemType3:
                ItemType3:
                ItemType3:
                ItemType3:


<ItemType1@Button>
    text: 'New Button'
    background_color: 0, 0, 0, 0
    background_normal: ''
    size_hint: None, None
    size: 220, 220
    pos_hint: {'center_x': 0.5, 'y': 1}

    canvas.before:
        Color:
            rgba: 96/255, 21/255, 21/255, 0.50
        RoundedRectangle:
            pos: self.pos
            size: self.size
            radius: [50]
        Color:
            rgba: 168/255, 0/255, 0/255, 1
        Line:
            width: 2
            rounded_rectangle: (self.x, self.y, self.width, self.height, 50)

我不知道,我尝试使用 size_hint,但没有任何效果。你能告诉我如何做第二张照片吗

python kivy kivy-language kivymd kivy-recycleview
1个回答
0
投票

尝试添加:

            Widget:
                size_hint: None, None
                size: 200, 200

在每个垂直

BoxLayouts
的末尾有足够的时间,以便 3 个
BoxLayouts
中的每一个都有相同数量的子项。

© www.soinside.com 2019 - 2024. All rights reserved.