首页 > 解决方案 > 如何在kivy中使用“if,else if,else”条件

问题描述

如何在 kivy 中创建条件文本标签,例如 if x=1 text='Hi' if x=2 text='Hello' if x=1 text='helloword'

Label:
    text:'hi' if root.x=='1''hello' elseif root.x=='1' else 'helloworls'

像这样的东西

标签: pythonkivy

解决方案


之后的部分text:是 Python 语法(不是特定于 kivy 的):
text:'hi' if root.x=='1' else 'hello' if root.x=='2' else 'helloworls'


推荐阅读