问题
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