파이썬[Python]: kivy - bind 함수 with Animation_0001
kivy.event 모듈 - EventDispatcher 클래스 - bind 함수(functions)
/// 설명
이벤트 타입이나 속성을 callback 함수에 연결합니다.
Event: on_start, on_complete, on_progress
참고: event 모듈 목록
※ 형식
bind(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.event.html
Event: on_start, on_complete, on_progress
참고: event 모듈 목록
※ 형식
bind(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.event.html
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.core.window import Window from kivy.uix.floatlayout import FloatLayout from kivy.animation import Animation from kivy.uix.button import Button Window.clearcolor = (.5, .0, .5, .1) class TestApp(App): def bt_pressed(self, button_instance): # getting window size window_width, window_height = Window.size def ani_start(ani_instance, button_instance): self.bt2.text = 'Moving' def ani_end(ani_instance, button_instance): self.bt2.text = 'The End' anmt = Animation(y=window_height-100) # first move(up) anmt.bind(on_start=ani_start) anmt += Animation(x=window_width-100) # second move(right) anmt += Animation(y=0) # third move(down) anmt += Animation(x=0) # forth move(left) anmt.bind(on_complete=ani_end) anmt.start(button_instance) return None def build(self): fl = FloatLayout() # FloatLayout - Button1 - Start bt1 = Button(text='Animation!!!', size_hint=(None, None), size=(100, 100), on_press=self.bt_pressed) # FloatLayout - Button1 - End ---------- # FloatLayout - Button2 - Start bt2 = Button(text='None!!!', size_hint=(None, None), size=(200, 200), pos=(300, 200)) self.bt2 = bt2 # FloatLayout - Button2 - End ---------- # FloatLayout fl.add_widget(bt1) fl.add_widget(bt2) return fl TestApp().run() | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기