Lev Barenboim
Lev Barenboim

Reputation: 119

Unexpected TypeError while calling ScreenManager.get_screen() function

I am trying to use get_screen() function to get a screen with the name given in a form of string. Annoyingly, though, I keep on getting a

 TypeError: 'kivy.properties.ListProperty' object is not iterable

error. I have no idea what I am doing wrong. Here's an MRE:

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder

class WindowManager(ScreenManager):
    pass

class Screen_One(Screen):
    def button(self):
        return WindowManager.get_screen(WindowManager,'Two')

class Screen_Two(Screen):
    pass

class Application(App):
    def build(self):
        return design

if __name__ == '__main__':
    with open('design.txt', encoding='utf-8') as f:
        design = f.read()
    design = Builder.load_string(design)
    Application().run()

...and the kv...

WindowManager:
    Screen_One:
    Screen_Two:

<Screen_One>:
    name: 'One'
    Button:
        size_hint: (0.2, 0.2)
        on_release:
            root.button()

<Screen_Two>:
    name: 'Two'

Edit: I tried changing the code on assumption that get_screen() function works with the class names of screens, and not actual screen names defined in kv. Still nothing.

Upvotes: 1

Views: 89

Answers (1)

eyllanesc
eyllanesc

Reputation: 244359

To use get_screen() you have to use the object created from the WindowManager class, not the class. If you want to get the manager associated with a screen then you must use the manager property:

class Screen_One(Screen):
    def button(self):
        return self.manager.get_screen('Two')

Upvotes: 1

Related Questions