我是Kivy新手,我正在尝试编写包含一些可重用部分的应用。 我的想法是编写带有所有“静态”部分的模板规则,并仅更新我感兴趣的领域。 这里的HomeScreen和SecondScreen是ScreenManager中使用的屏幕,这只是我的.kv文件的相关部分
#kvlang
<ScreenTemplate@BoxLayout>:
orientation: "vertical"
rows: 2
TopRowMain:
size_hint: (1, 0.2)
BoxLayout:
orientation: "horizontal"
BoxLayout:
size_hint: (0.7, 1)
StyledButton: ###<-- i want to change this widget
text: root.buttontext
on_press: root.open_deck()
BoxLayout: #select drink / custom drink area
orientation:"vertical"
StyledButton:
text: "select drink"
StyledButton:
text: "custom drink"
<HomeScreen>: #slide 1
ScreenTemplate:
buttontext : 'meh'
<SecondScreen>: #slide 2
ScreenTemplate:
buttontext : '2nd screen'
上面的代码工作正常。但我想做些更广泛的事情。就像完全替换标记区域中的小部件(可能与StyledButton有所不同)之类的东西,或者至少使用放置在父BoxLayout中的ID(我可以以某种方式调用它)并设置所有小部件属性,而不必创建每个属性的标签。
我了解如何在python中执行此操作,但是我想在.kv文件中指定所有屏幕,以提高可读性。