Kivy slider event on_release

匆匆过客 提交于 2019-12-11 03:57:37

问题


I'm pretty new to Kivy and I'm trying to use the Slider widget. I don't want a function to be executed on_value but rather as soon as the slider is released. How can I implement something like on_release (which exists for Buttons) in the Slider class?

I.e. instead of

Slider:
    on_value: root.do_something()

I want to have

Slider:
    on_release: root.do_something()

回答1:


I don't think there's a built in event for this, so you'd need to override on_touch_up. Something like the following should work:

def on_touch_up(self, touch):
    released = super(YourSliderSubclass, self).on_touch_up(touch)
    if released:
        do_something()
    return released

This works because its on_touch_up returns True by default if it was actually released, otherwise it returns None.

If you want an event to bind to in kv, you could add your own new event to your slider subclass and dispatch that.



来源:https://stackoverflow.com/questions/32127576/kivy-slider-event-on-release

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!