2016-02-26 64 views
3

我有两个屏幕。当我按下“下一个屏幕”按钮时,它将进入第二个屏幕,过渡应该是SlideTransition(左侧),当我按下“后退”按钮时,它应该回到第一个屏幕,过渡应该是SlideTransition(右侧)。Kivy - 如何更改不同屏幕中的屏幕过渡

怎么办?它仅使用在我的代码

1个过渡这是我的代码PY/KV代码:

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() 

回答

3

把转变中on_release事件。

Button: 
    text: 'next screen' 
    on_release: 
     app.root.transition = SlideTransition(direction='right') 
     app.root.current = '2ndScreen' 
... 
+0

工作!谢谢! – KPA