2016-02-26 78 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