파이썬[Python]: kivy - Callback 클래스
kivy.graphics 모듈 - Callback 클래스(class)
/// 설명
1초에 한번씩 callback 함수를 호출합니다.
참고: graphics 모듈 목록
※ 형식
Callback(callback=None, **kwargs)
reference
https://kivy.org/doc/stable/api-kivy.graphics.html
참고: graphics 모듈 목록
※ 형식
Callback(callback=None, **kwargs)
reference
https://kivy.org/doc/stable/api-kivy.graphics.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 63 64 65 66 67 68 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.base import EventLoop from kivy.core.window import Window from kivy.graphics import RenderContext, Color, Rectangle, \ Callback, Rotate from kivy.uix.widget import Widget Window.clearcolor = (1, 1, 1, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 2900 fs = ''' $HEADER$ void main(void) { gl_FragColor = texture2D(texture0, tex_coord0); } ''' class CustomWidget(Widget): def __init__(self, **kwargs): # Before doing anything, ensure the windows exist. EventLoop.ensure_window() self.texture() # drawing self.bind(size=self._update_pos) # get real size of class CustomWidget super(CustomWidget, self).__init__(**kwargs) def _update_pos(self, instance, value): self.rect.pos = self.center self.rt.origin = self.center def _my_callback(self, inst): self.canvas.remove(self.rect) self.canvas.add(Rotate(angle=45, origin=self.center)) self.rect = Rectangle(source='./football.png', size=(250, 30), pos=self.center) self.canvas.add(self.rect) def texture(self, *args): # all the necessary information for drawing self.canvas = RenderContext() # set shader.fs self.canvas.shader.fs = fs with self.canvas: Color(0, 1, 1, 1) self.rt = Rotate(angle=-45, origin=self.center) self.rect = Rectangle(source='./football.png', size=(250, 30), pos=self.center) Callback(self._my_callback) # call _my_callback() every 1 second # the default vertex shader self.canvas['projection_mat'] = Window.render_context['projection_mat'] class FantasticApp(App): def build(self): return CustomWidget() FantasticApp().run() | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기