Kivy 在一个类中有on_touch_down或者on_touch_move函数时,类中添加的Button的响应函数不给予响应

在Kivy应用中遇到按钮响应被on_touch_down方法中断的问题,原因是on_touch_down优先执行并覆盖了按钮事件。解决方案是在a类的on_touch_down方法末尾调用super(a, self).on_touch_down(touch),这样可以保持事件链的正常传递。
摘要由CSDN通过智能技术生成

问题原因:on_touch ...方法在触摸事件链中首先执行,会将button响应覆盖,您会中断该链。

解决办法:只需添加super()即可继续。即在原有touch函数中添加最后一行。

class a(Widget):
    def on_touch_down(self, touch):
        print "touch x is ",touch.x
        print "touch y is ",touch.y
        # add this line:
        super(a, self).on_touch_down(touch) 

参考:Kivy中绑定按钮的On_Release事件不起作用-运行on_touch_down - On_Release event of bind button in kivy not working - running on_touch_down - 堆栈内存溢出 (stackoom.com) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值