Python | ScreenManager in Kivy using .kv file
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
ScreenManager widget :
The screen manager is a widget which is used to managing multiple screens for your application. The default ScreenManager displays only one Screen at a time and uses a TransitionBase to switch from one Screen to another. Multiple transitions are supported.
The ScreenManager and Screen class are imported. The ScreenManager will be used for the root like:
from kivy.uix.screenmanager import ScreenManager, Screen
Note:The default ScreenManager.transition is a SlideTransition with options direction and duration.
Basic Approach: 1) import kivy 2) import kivyApp 3) import Screen Manager, Screen, ""Transitions you want to use"" 4) Set minimum version(optional) 5) Create Different Screen classes and pass them 6) Create features of Screen classes in .kv file :: Add features in different screens 7) Create App class 8) return screen manager 9) Run an instance of the class
Below is the implementation of the code with .kv file in .py file.
You have multiple transitions available by default, such as:
- NoTransition – switches screens instantly with no animation
- SlideTransition – slide the screen in/out, from any direction
- CardTransition – new screen slides on the previous or the old one slides off the new one depending on the mode
- SwapTransition – implementation of the iOS swap transition
- FadeTransition – shader to fade the screen in/out
- WipeTransition – shader to wipe the screens from right to left
- FallOutTransition – shader where the old screen ‘falls’ and becomes transparent, revealing the new one behind it.
- RiseInTransition – shader where the new screen rises from the screen center while fading from transparent to opaque.
You can easily switch transitions by changing the ScreenManager.transition property:
sm = ScreenManager(transition=FadeTransition())
Note: Code is Same some points is added in code don’t confuse.
Output Video of Different transitions –