Kivy v1.11.1嵌套框布局

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

我使用Kivy创建了嵌套的框布局,该布局有效。但是我需要在我的Python代码中调用三个类。有没有更优雅的方式做到这一点?例如。在Python中只有一个类?

Python代码:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

class HorizLayout1(BoxLayout):
    pass
class HorizLayout2(BoxLayout):
    pass

class VertLayout(BoxLayout):
    pass


class KivyTestsApp(App):
    def build(self):
        return VertLayout()

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

kivytests.kv:

<HorizLayout1>:
    orientation: "horizontal"
    Button:
        text: "1"
    Button:
        text: "2"

<HorizLayout2>:
    orientation: "horizontal"
    Button:
        text: "3"
    Button:
        text: "4"

<VertLayout>:
    orientation: "vertical"
    HorizLayout1:
    HorizLayout2:
python nested kivy boxlayout
1个回答
0
投票

您的py可能是这个:

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

class VertLayout(BoxLayout):
    pass

class KivyTestsApp(App):
    def build(self):
        return VertLayout()

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

...,您的kv可能是这个:

<VertLayout>:
    orientation: "vertical"
    BoxLayout:
        Button:
            text: "1"
        Button:
            text: "2"
    BoxLayout:
        Button:
            text: "3"
        Button:
            text: "4"
© www.soinside.com 2019 - 2024. All rights reserved.