파이썬[Python]: kivy - FocusBehavior 클래스 - kv
kivy.uix.behaviors.focus 모듈 - FocusBehavior 클래스(class)
/// 설명
가시적인 위젯에 포커스를 제공합니다.(다른 클래스와 같이 사용하셔도 됩니다.)
참고: uix 모듈 목록
※ 형식
FocusBehavior(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.uix.behaviors.focus.html
참고: uix 모듈 목록
※ 형식
FocusBehavior(**kwargs)
reference
https://kivy.org/doc/stable/api-kivy.uix.behaviors.focus.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 | import kivy kivy.require('2.0.0') from kivy.app import App from kivy.core.window import Window from kivy.uix.behaviors.focus import FocusBehavior from kivy.uix.button import Button from kivy.lang import Builder Window.clearcolor = (.6, 1, .8, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 700 kv = ''' GridLayout: cols: 3 FocusButton: text: '0' on_press: app._bt_press(root) FocusButton: text: '1' on_press: app._bt_press(root) FocusButton: text: '2' on_press: app._bt_press(root) FocusButton: text: '3' on_press: app._bt_press(root) FocusButton: text: '4' on_press: app._bt_press(root) FocusButton: text: '5' on_press: app._bt_press(root) ''' class FocusButton(FocusBehavior, Button): pass class FantasticApp(App): def _bt_press(self, gl): for i in gl.children: if i.focus is True: i.background_color = (1, 0, 0, 1) else: i.background_color = (1, 1, 1, 1) def build(self): return Builder.load_string(kv) FantasticApp().run() | cs |
/// 출력
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기