내 애플리케이션에서 동적으로 생성 된 라벨 중 하나를 터치하면 일부 기능을 호출하려고합니다.버튼의 'on_release'이벤트는 동적으로 생성 된 모든 라벨의 'on_touch_up'이벤트를 호출합니다.
#if not instance.collide_point(*touch.pos):
# return
버튼을 뒤에 레이블 : 내가 사용하는 경우
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.logger import Logger
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
Builder.load_string("""
<Root>:
BoxLayout:
orientation: 'vertical'
size_hint: 1, 1
ScrollView:
id: scroll_view
size_hint: 1,.9
do_scroll_x: False
BoxLayout:
orientation: 'horizontal'
size_hint: 1,.1
Button:
id: bt1
text: 'Click'
size_hint: 1,1
on_release: root.btn1_click()
""")
class Root(BoxLayout):
def btn1_click(self):
Logger.info('BUTTON: button was released')
class TestApp(App):
def callback(self, instance, touch):
#if not instance.collide_point(*touch.pos):
# return
Logger.info('LABEL: ' + instance.text + 'was released')
def build(self):
root = Root()
sv = root.ids.scroll_view
grid = GridLayout(cols=1, spacing=(0,10), size_hint_y=None,
padding = [10,10,10,10],row_force_default=True, row_default_height=50)
grid.bind(minimum_height=grid.setter('height'))
sv.add_widget(grid)
for tr in [i for i in range(50)]:
lb_text = str(tr) + ' ' + 'Label'
lb = Label(text=lb_text)
lb.bind(on_touch_up=self.callback)
grid.add_widget(lb)
return root
if __name__ == '__main__':
TestApp().run()
그리고 : 그리고 거기에 모든 레이블라는 이벤트 on_touch_up I 버튼을 누르면 다른 function.But를 호출 하단에 버튼입니다 이 버튼이 눌러집니다. 이 터치를 올바르게 처리하려면 어떻게해야합니까?
주석 처리를 취소하고 처리기에 True를 반환했지만 스크롤 뷰의 size_y를 10으로 설정하고 버튼과 스크롤 뷰 사이에 분리 위젯을 추가하더라도 스크롤 뷰의 이러한 레이블은 여전히 버튼 뒤에 있습니다. 그래서 버튼을 클릭하면 뒤에 보이지 않는 라벨이 클릭됩니다. ( – Freest
@Freest 죄송합니다. 터치 다운 대신 터치 업 이벤트를 사용하고 있음을 확인하지 못했습니다. 내 대답을 업데이트했습니다. –