파이썬[Python]: kivy - StencilView 클래스
kivy.uix.stencilview 모듈 - StencilView 클래스(class)
/// 설명
하위 위젯들이 그래픽을 사용하는데 한계를 설정합니다.(StencilView's bounding box)
참고: uix 모듈 목록
※ 형식
StencilView(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.uix.stencilview.html
참고: uix 모듈 목록
※ 형식
StencilView(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.uix.stencilview.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 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout from kivy.uix.stencilview import StencilView from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Rectangle from functools import partial from random import random Window.clearcolor = (.6, 1, .8, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 700 class TestBoxStencil(BoxLayout, StencilView): def _bt_press(self, wg, bt_instance): print(wg.x, wg.y) with wg.canvas: for i in range(100): Color(random(), 1, 1, mode='hsv') Rectangle(pos=(random() * 1000 + wg.x, random() * 1000 + wg.y), size=(20, 20)) def __init__(self, **kwargs): super(TestBoxStencil, self).__init__(**kwargs) wg = Widget() bt = Button(text='+ 100 Rectangles', on_press=partial(self._bt_press, wg)) self.add_widget(wg) self.add_widget(bt) class FantasticApp(App): def build(self): return TestBoxStencil(orientation='vertical', pos=(50, 50), size_hint=(None, None), size=(Window.size[0] - 100, Window.size[1] - 100)) FantasticApp().run() | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기