[英]Exchanging variables between kivy widgets
I wanted to make a program with an kivy widgets in multiple box Layouts and I wanted to acsess properties of the root widget(level) from the Feld class. 我想用多个框式布局制作一个带有奇异果小部件的程序,并且想从Feld类中访问根小部件(级别)的属性。 But
root.ids.level
did not worked. 但是
root.ids.level
无法正常工作。 Here is my code: 这是我的代码:
class level(BoxLayout):
kr = StringProperty('kreuz.png')
ks = StringProperty('kreis.png')
class Feld(Widget):
weg = StringProperty('hinterg.png')
def on_touch_down(self, touch):
if self.ids.my_image.collide_point(*touch.pos):
self.weg = root.ids.level.kr
root = Builder.load_string('''
level:
id: level
<level>:
orientation: 'vertical'
BoxLayout:
id: box1
orientation: 'horizontal'
Feld:
pos: 100, 310
id: a1
<Feld>:
Image:
pos: root.pos
id: my_image
source: root.weg
''')
class TTT(App):
def build(self):
return root
if __name__ == "__main__":
TTT().run()
The root
keyword refers to the root of the current kv rule, not the root widget of the application. root
关键字是指当前kv规则的根,而不是应用程序的根小部件。 You can use app.root
instead. 您可以改用
app.root
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.