In this video I’ll show you how to scroll between multiple windows or screens with ScreenManager for Kivy and Python.
Kivy isn’t great at allowing you to create multiple windows. But what it DOES allow you to do is create multiple “screens” inside your main window, and that’s what we’ll do in this video.
We’ll use ScreenManager to manage our different screens, and I’ll show you how to scroll between them with the click of a button.
Python Code: new_window.py
GitHub Code: new_window.py
from kivy.app import App from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen #Define our different screens class FirstWindow(Screen): pass class SecondWindow(Screen): pass class WindowManager(ScreenManager): pass # Designate Our .kv design file kv = Builder.load_file('new_window.kv') class AwesomeApp(App): def build(self): return kv if __name__ == '__main__': AwesomeApp().run()
Kivy Design Code: new_window.kv
GitHub Code: new_window.kv
WindowManager: FirstWindow: SecondWindow: <FirstWindow>: name: "first" BoxLayout: orientation: "vertical" size: root.width, root.height Label: text: "First Screen" font_size: 32 Button: text: "Next Screen" font_size: 32 on_release: app.root.current = "second" root.manager.transition.direction = "left" <SecondWindow>: name: "second" BoxLayout: orientation: "vertical" size: root.width, root.height Label: text: "Second Screen" font_size: 32 Button: text: "Go Back" font_size: 32 on_release: app.root.current = "first" root.manager.transition.direction = "right"
Add comment