You could do something like this… but doing it with the bind is correct.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
class RootWidget(BoxLayout):
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
self.add_widget(Button(text='btn 1'
))
cb = CustomBtn(touch_action=self.btn_pressed)
# cb.bind(on_test=self.btn_pressed)
self.add_widget(cb)
self.add_widget(Button(text='btn 2'))
def btn_pressed(self, *arg):
print('clicked ', *arg)
class CustomBtn(Widget):
touch_action = ObjectProperty(None, allownone=True)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.register_event_type('on_test')
def on_touch_up(self, touch):
if self.collide_point(*touch.pos):
self.dispatch('on_test')
return True
return super(CustomBtn, self).on_touch_down(touch)
def on_test(self, *args):
print('on_test fired')
if self.touch_action:
self.touch_action(*args)
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ffa9346c-5c6e-419d-9adb-aaf026348b39o%40googlegroups.com.