Kivy - 从Toggle Buttons Group获得价值

时间:2018-01-17 18:18:17

标签: python kivy kivy-language

我从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()

0 个答案:

没有答案