1

I'm trying to transition between screens but my screen manager is failing, saying that it has a type of NoneType. I suspect I may be failing to refer to my screen manager properly? What would be the correct approach for this?

The approach I've taken is straight from the documentation, so I'm unsure where I'm going wrong.

Error:

      on_release: root.manager.current = 'AboutUsWindow'
 AttributeError: 'NoneType' object has no attribute 'current'

My .kv file:

<MainWindow>:
    name: "MainWindow"
    BoxLayout:
        orientation: "horizontal"
        ActionBar:
            pos_hint: {'top':1}
            use_separator: True
            background_color: 0, 1, 1, 1
            ActionView:
                use_separator: True
                ActionPrevious:
                    with_previous: True
                ActionOverflow:
                    ActionButton:
#                       text: "some text"
                        text: root.name
                        on_release: root.manager.current = 'AboutUsWindow'
                    ActionButton:
                        text: "sponsors"
                        on_release: root.manager.current = 'AboutUsWindow'
                    ActionButton:
                        text: "contact"
                    ActionButton:
                        text: "event"


<AboutUsWindow>:
    name: "AboutUsWindow"
    Label:
        text: "asdasdasd"
    Button:
        size: (123,123)

My main.py file:

# Here are imports which i did not include
class MainWindow(Screen, BoxLayout, CoverImage):
    pass


class AboutUsWindow(Screen, BoxLayout, CoverImage):
    pass


sm = ScreenManager()
sm.transition = FadeTransition()
sm.add_widget(MainWindow())
sm.add_widget(AboutUsWindow())

class PystokApp(App):
    def build(self):
        root = MainWindow(source='images/logo.jpg')
        return root
        # main = MainWindow()
        # Window.size = main.size
        # return MainWindow()

if __name__ == "__main__":
    PystokApp().run()
4
  • 1
    Your multiple inheritance may be a recipe for disaster. Generally you should inherit from just one widget type, and add instances of the others to the widget. Commented Apr 15, 2015 at 14:32
  • @inclement I don't think this is necessarily true, if two widgets do different things there should be no problem of inheriting from both. One problem could be that Screen itself is a subclass of RelativeLayout and additionally inheriting from BoxLayout might break things. Commented Apr 15, 2015 at 14:37
  • It's not necessarily true, hence only a recipe for disaster. Since widget composition isn't intended to work this way, we don't make much effort to avoid problems though, which is why I recommend avoiding it even if it works in some cases. Commented Apr 15, 2015 at 14:39
  • @inclement I was under the impression that some stock widgets are implemented through multiple inheritance e.g. ScatterLayout, but it seems that I was wrong. My mistake, sorry. Commented Apr 15, 2015 at 17:27

2 Answers 2

2

You do not use your ScreenManager. You create a ScreenManager sm and add screen to it, but after that you don't use it but instead create a new MainScreen (which is not linked to your manager). Your root Widget should be your screen manager, that means your build() function should return the ScreenManager. In the documentation this is archieved with return(sm).

Also you need to name your screens when you create them. You can do this by Screen(name="myscreen"), otherwise your manager will not know that names corrospond to which screens.

Sign up to request clarification or add additional context in comments.

2 Comments

But when I return my screenmanager instead of my MainWindow the app goes blank. And I want to it display my MainWindow. I tried to add my screenmanager to my mainwindow as a widget but they the app went white again. Im passing names in my .kv file.
It works for me if you put the sm = ScreenManager(); sm.add_widget(...)...into the def build(self): function. I can't explain why though.
0

Your app might not be showing screens because even when you add them to your screen manager your PystokApp() class is not returning the screen manager.

Instead of return root, try return sm.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.