我使用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:
您的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"