파이썬[Python]: kivy - Clock 인스턴스 - kv
kivy.clock 모듈 - Clock 객체(Instance)
/// 설명
시간 간격에 따라 함수를 호출합니다.(한번만 호출할 수도 있습니다.)
참고: animation to gesture 모듈 목록
※ 형식
Clock
reference
https://kivy.org/doc/stable/api-kivy.clock.html
참고: animation to gesture 모듈 목록
※ 형식
Clock
reference
https://kivy.org/doc/stable/api-kivy.clock.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 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.core.window import Window from kivy.clock import Clock from kivy.lang import Builder Window.clearcolor = (1, 1, 1, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 700 kv = ''' BoxLayout: orientation: 'vertical' Label: id: id_lb text: '0' color: 'black' Button: text: 'Start' on_press: app._bt_start(self) ''' class FantasticApp(App): _float = 0 def _bt_start(self, bt_instance): if bt_instance.text == 'Start': # call _clock_call() every 0.1 seconds self.event = Clock.schedule_interval(self._clock_call, 0.1) bt_instance.text = 'Stop' else: self.event.cancel() bt_instance.text = 'Start' def _clock_call(self, clock_instance): self._float += 0.1 self.root.ids.id_lb.text = '{:.1f}'.format(self._float) def build(self): return Builder.load_string(kv) FantasticApp().run() | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기