我正在试图弄清楚如何只在某个按钮按下时更改屏幕方向动画(取消按钮应该向右擦除而不是向左按下前导航按钮。)这是我目前正在做的事情让这件事发生:
# Cancel Button
self.cancel = Button(text="Cancel", height=30, width=90,size_hint=(None, None),pos=(300, 350))
self.cancel.bind(on_release=self.BackFunction)
self.ids.float_web.add_widget(self.cancel)
def BackFunction(self, *args):
self.manager.transition.direction = 'right'
self.manager.current = ('input_sc')
我想知道在这个动画发生后如何重置左边的方向。如果我按照
更改屏幕self.manager.transition.direction = 'left'
然后它只是将方向留在BackFunction
内由于
答案 0 :(得分:1)
我认为每次更改direction
属性时最好定义current
属性。但是,您可以执行将函数绑定到on_complete
事件并在函数本身内取消绑定的操作:
示例:强>
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
kv_text='''\
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
<MyScreenManager>:
transition: SlideTransition()
FirstScreen:
LastScreen:
<FirstScreen@Screen>:
name: 'first_sc'
BoxLayout:
Button:
text: 'Next'
on_release: root.next_screen()
<LastScreen@Screen>:
name: 'last_sc'
BoxLayout:
Button:
text: 'Previous'
on_release: root.previous_screen()
'''
class MyScreenManager(ScreenManager):
pass
class FirstScreen(Screen):
def __init__(self, **kwargs):
super(FirstScreen, self).__init__(**kwargs)
def next_screen(self, *args):
self.manager.current = 'last_sc'
class LastScreen(Screen):
def __init__(self, **kwargs):
super(LastScreen, self).__init__(**kwargs)
def previous_screen(self, *args):
self.manager.transition.direction = 'right'
self.manager.current = 'first_sc'
self.manager.transition.bind(on_complete=self.restart)
def restart(self, *args):
self.manager.transition.direction = 'left'
self.manager.transition.unbind(on_complete=self.restart)
class MySubApp(App):
def build(self):
return MyScreenManager()
def main():
Builder.load_string(kv_text)
app = MySubApp()
app.run()
if __name__ == '__main__':
main()