Reputation: 1966
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()
Upvotes: 1
Views: 3335
Reputation: 207
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.
Upvotes: 0
Reputation: 7384
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.
Upvotes: 2