I have two screen. When I press the 'next screen' button it will go to the 2nd screen and the transition should be SlideTransition (left) and when I press the 'back' button it should go back to the 1st screen and the transition should be SlideTransition (right).
How to do it? it only uses 1 transition in my code
This is my code py/kv code:
class 1stScreen(Screen):
...some methods...
class 2ndScreen(Screen):
...some methods...
class MyScreenManager(ScreenManager):
pass
root_widget = Builder.load_string('''
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
MyScreenManager:
transition: SlideTransition(direction='left')
1stScreen:
transition: SlideTransition(direction='right') #<-- Im getting error with this
2ndScreen:
<1stScreen>:
name: '1stScreen'
...some widgets...
Button:
text: 'next screen'
on_release: app.root.current = '2ndScreen'
<2ndScreen>:
name: '2ndScreen'
...some widgets...
Button:
text: 'back'
on_release: app.root.current = '1stScreen'
''')
class Main(App):
def build(self):
return root_widget
if __name__ == "__main__":
Main().run()
To switch displays, hold down the left CTRL key + left Windows Key, and use the left and right arrow keys to cycle through the available displays.
Put the transitions in on_release
events.
Button:
text: 'next screen'
on_release:
app.root.transition = SlideTransition(direction='right')
app.root.current = '2ndScreen'
...
For anyone else coming here looking for the answer to use entirely different transitions from one screen to another, this is what worked for me:
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#: import SlideTransition kivy.uix.screenmanager.SlideTransition
app.root.transition = FadeTransition(duration=1.2)
Keep it linked with your triggering event. I tried
on_release
for my login and sign off buttons but found that it was glitchy and not exactly the behavior I was going for. I ended up adding a line for
on_press
in order to create the desired transitions without the unexpected behavior. I kept the actual line that changes the screen under the
on_release
line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With