python Kivy BoxLayout设置高度等于儿童身高

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Kivy BoxLayout设置高度等于儿童身高相关的知识,希望对你有一定的参考价值。

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


Builder.load_string("""
<LayoutTest>:
    orientation: 'vertical'
    padding: 20
    spacing: 10

    BoxLayout:
        orientation: 'horizontal'
        padding: 0
        spacing: 0
        size_hint_y: None   # I want the "row" height to be equal to the AsyncImage height (1/3rd screen width), see
                            # comment below

        AsyncImage:
            # I want this image to be 1/3rd screen width, hence the size_hint_x = 0.66, but I want the height of this
            # image to be equal to the width (also 1/3rd screen width).
            size_hint_x: 0.66
            source: 'http://placehold.it/400x400'
            allow_stretch: True

        Widget:
            canvas:
                Color:
                    rgba: 1, 0, 0, 0.2
                Rectangle:
                    size: self.size
                    pos: self.pos

    BoxLayout:
        orientation: 'horizontal'
        padding: 0
        spacing: 0

        Widget:
            size_hint_x: 0.1
            canvas:
                Color:
                    rgba: 1, 1, 0, 0.2
                Rectangle:
                    size: self.size
                    pos: self.pos

        Widget:
            canvas:
                Color:
                    rgba: 0, 1, 1, 0.2
                Rectangle:
                    size: self.size
                    pos: self.pos
""")


class LayoutTest(BoxLayout):
    pass


class MainApp(App):
    def build(self):
        return LayoutTest()


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

以上是关于python Kivy BoxLayout设置高度等于儿童身高的主要内容,如果未能解决你的问题,请参考以下文章

带有boxlayout的kivy滚动视图

Kivy 标签和弹出窗口 + 长文本

Kivy:BoxLayout 与 GridLayout

Kivy \\ 如何将按钮绑定到 boxlayout 的底部

Kivy:如何从自定义 BoxLayout 显示 ScrollView?

如何在 Kivy python 中最大化滚动条?