<MainToggle@ToggleButton>:
on_state: # something that will change the state of the sub-toggle
<SubToggle@ToggleButton>:
on_state: self.background_color = 0,0,0,1 # the sub-toggle button changes color
from kivy.base import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string("""
<MainToggle@ToggleButton>:
<SubToggle@ToggleButton>:
on_state: self.background_color = 0,0,0,1 # the sub-toggle button changes color
BoxLayout:
MainToggle:
id: my_toggle1 # an id allows us to refer to this widget
text: "Main Toggle"
# change the other toggle's state using its id
on_state: my_toggle2.state = "down" if my_toggle2.state == "normal" else "normal"
SubToggle:
id: my_toggle2
text: "Sub Toggle"
"""))
您可以使用kivyid系统引用其他小部件。遵守以下代码:
这里有一个极好的video教程,在一个实际例子中使用kivyid系统。回答,如果你有困难围绕着这个问题。在
相关问题 更多 >
编程相关推荐