I'm trying to switch between two screens.. but it doesn't work.. it didn't show anything or any error I don't know what is the problem, here's my code
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
class mainWindow(Screen):
pass
class secondWindow(Screen):
pass
class windowManager(ScreenManager):
pass
sm = ScreenManager()
sm.add_widget(mainWindow(name='main'))
sm.add_widget(secondWindow(name='second'))
class multApp(App):
def build(self):
return mainWindow()
if __name__ == "__main__":
multApp().run()
and mult.kv
windowManager:
mainWindow:
secondWindow:
<mainWindow>:
name: "main"
Button:
text: "Submit"
on_press : root.manager.current = "second"
<secondWindow>:
name: "second"
Button:
text: "go back"
on_press : root.manager.current = "main"
You have several issues in your code.
build()method returnsmainWindow(). This means that your app GUI consists of just aScreen(mainwindow) with noScreenManager. So theroot.manager.current =lines in yourkvwill fail because there is no manager.mult.kvfile contains a rule (windowManager:) for building the GUI, but this rule is over-ridden by yourbuild()method.sm = ScreenManager()) that also build the GUI, but you do nothing with the results of these lines. So those lines have no effect.kv, as you are, this is a requirement.Taking all this into account, here is a modified version of your code that should work:
python code:
mult.kv: