0

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. But root.ids.leveldid not worked. 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()
Gilgamesch
  • 313
  • 2
  • 10
  • 24
  • http://stackoverflow.com/questions/30202801/how-to-access-id-widget-of-different-class-from-a-kivy-file-kv **this should help.** – kiok46 May 29 '15 at 16:01

1 Answers1

0

The root keyword refers to the root of the current kv rule, not the root widget of the application. You can use app.root instead.

inclement
  • 29,124
  • 4
  • 48
  • 60