What I want to know?
It is explained (little) in this link, but not from the beginner's point of view.
I have 2 files
test.py
#PersSchemaTable td:nth-child(1),
#PersSchemaTable td:nth-child(3),
#PersSchemaTable td:nth-child(5),
#PersSchemaTable td:nth-child(7),
#PersSchemaTable td:nth-child(9),
#PersSchemaTable td:nth-child(11),
#PersSchemaTable td:nth-child(13) {
border-right: 2px solid #781351;
}
dates_test.kv file
class Get_People(BoxLayout):
pass
class Get_Boys(BoxLayout):
pass
class Get_Girls(BoxLayout):
pass
class TestApp(App):
def build(self):
self.load_kv('dates_test.kv')
return Get_People()
答案 0 :(得分:14)
嗯!看起来我自己找到了答案,我想分享一下。
首先让我们在dates_test.kv文件中给出“id”。这样您就可以在python代码或.kv文件中访问它们。
<Get_People>:
stuff_p: root_lbl
...
Get_Boys:
id: gb
Get_Girls:
id: gg
<Get_Boys>:
stuff_b: label_b
<Get_Girls>:
stuff_c: label_g
你可能想知道什么是stuff_p,stuff_b和stuff_c ???
它们是在自己的类中定义的ObjectProperty。您在python代码中的stuff_b中所做的更改会在label_b中进行更改,因为您已在kivy文件中进行了链接。
class Get_People(BoxLayout):
stuff_p = ObjectProperty(None)
...
class Get_Boys(BoxLayout):
stuff_b = ObjectProperty(None)
...
class Get_Girls(BoxLayout):
stuff_c = ObjectProperty(None)
...
对于第1部分和第2部分
如果释放了带有id:button_b(Get_Boys类)的按钮,则为Label id:label_g(Get_Girls类)必须更改。
- 醇>
如果按下具有id:button_b(Get_Boys类)的Button,则为Label id:root_lbl(Get_People类)必须更改。
在Get_Boys类(test.py)中定义这些方法。
def change_girl(self):
self.parent.ids.gg.stuff_c.text = "Boys changed Girls!"
#self.stuff_b.text = "i changed myself!"
def change_people(self):
self.parent.ids.root_lbl.text = "Boys changed people!"
让我们看看这里发生了什么......
self.parent.ids.gg.stuff_c.text =“男孩改变了女孩!”
并在.kv文件中
<Get_Boys>:
stuff_b: label_b
Button:
id: button_b
text: "button 1"
on_release: root.change_girl()
on_press: root. change_people()
第3部分
- 如果释放了具有id:root_btn(Get_People类)的Button,则为Label id:label_b(Get_Boys类)必须更改。
醇>
在Get_People类(test.py)中定义一个方法。
def rooted(self):
self.ids.gb.stuff_b.text = "people changed boys!"
和.kv文件
Button:
id: root_btn
text: "I am Root"
on_release: root.rooted()