我从Kivy开始。我想创建一个toogle按钮组,并根据按下哪个按钮获取值。
我的代码正在运行,但我想知道是否有另一种方法可以做到这一点。
这是我的代码:
" building.kv"文件:
#:kivy 1.10
<CategoryButton@ToggleButton>:
size_hint: None, None
size: 48,48
markup: True
group: 'category'
<Category@BoxLayout>:
orientation: 'horizontal'
current_value: 1
CategoryButton:
text: '[b]I[/b]'
on_press: root.current_value = 1
CategoryButton:
text: '[b]II[/b]'
on_press: root.current_value = 2
CategoryButton:
text: '[b]III[/b]'
on_press: root.current_value = 3
CategoryButton:
text: '[b]IV[/b]'
on_press: root.current_value = 4
Label:
text: str(root.current_value)
&#34; buildingmodule.kv&#34;文件:
#:kivy 1.10
<BuildingWind>:
orientation: 'vertical'
Category:
python文件
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
class BuildingWind(BoxLayout):
pass
def build(self):
return BuildingWind()
if __name__ == "__main__":
aplication = BuildingModuleApp()
aplication.run()