I'm writing a python script with a kv script outside it for formatting.
I have 2 basic screens thus far. I can load 1 screen into a preview but things fall apart when I try 2 screens.
I get this error:
kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.
Here's my python code:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
Builder.load_file("design.kv")
class Intro(Screen):
def go_settings(self):
self.manager.current = "settings"
pass
class Settings(Screen):
print("In settings")
pass
class RootWidget(ScreenManager):
pass
class MainApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
MainApp().run()
My kv code, titled "design.kv":
<Intro>:
GridLayout:
cols: 1
Label:
text: "Intro"
Button:
text: "Settings"
on_press: root.go_settings()
<Settings>:
GridLayout:
cols: 1
Label:
text: "Settings"
<RootWidget>:
Intro:
name: "intro"
Settings: #will work if I comment this line and below
name: "settings"
Not sure what's going on. Thanks for the help!
Alright, I think I got it.
I need to change the names of
Intro
and
Settings
to
IntroScreen
and
SettingsScreen
It seemed to work for me. Never thought the name I'd give would matter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.