nxe*_*xet 6 python kivy kivy-language
在Kivy,是否可以采用类似于以下示例的方法?
发布的代码显然不起作用,而且它只是一个例子:我需要根据某个属性绘制不同的布局.
你会怎么建议这样做?
BoxLayout:
number: 0
if self.number > 3:
Label:
text: 'number is bigger than 3'
Button:
text: 'click here to decrease'
on_press: root.number -= 1
else:
Label:
text: 'number is smaller than 3'
Button:
text: 'click here to increase'
on_press: root.number += 1
Run Code Online (Sandbox Code Playgroud)
我会使用 ScreenManager 或 Carousel,一个简单的例子可能是:
Carousel:
index: 1# or a "certain property" :)
scroll_timeout: 0.0 # disable the user ability to mess with the widgets layout
BoxLayout: #first option
Label:
Button:
BoxLayout: #2nd option
Button:
Label:
Run Code Online (Sandbox Code Playgroud)
如果您将索引绑定到您选择的属性,它将自动切换布局:)...
基于ScreenManager的方法将非常相似,主要的变化是仅绑定current_screen属性而不是索引
| 归档时间: |
|
| 查看次数: |
1559 次 |
| 最近记录: |