Created
August 20, 2015 22:54
-
-
Save hchandad/b71ed0e977e6d345bcb8 to your computer and use it in GitHub Desktop.
a simple display of a Slider with a on_release event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from kivy.app import App | |
from kivy.uix.slider import Slider | |
from kivy.uix.boxlayout import BoxLayout | |
class ModifiedSlider(Slider): | |
def __init__(self, **kwargs): | |
self.register_event_type('on_release') | |
super(ModifiedSlider, self).__init__(**kwargs) | |
def on_release(self): | |
pass | |
def on_touch_up(self, touch): | |
super(ModifiedSlider, self).on_touch_up(touch) | |
if touch.grab_current == self: | |
self.dispatch('on_release') | |
return True | |
def callback_release(instance): | |
print('The Slider object {} is released'.format(instance)) | |
def callback_value(instance, value): | |
print('The slider {} value changed to: {}'.format(instance, value)) | |
modified_slider_instance = ModifiedSlider() | |
modified_slider_instance.bind(on_release=callback_release) | |
modified_slider_instance.bind(value=callback_value) | |
slider_instance = Slider() | |
slider_instance.bind(value=callback_value) | |
class TestSlider(App): | |
def build(self): | |
root = BoxLayout(orientation='vertical') | |
root.add_widget(modified_slider_instance) | |
root.add_widget(slider_instance) | |
return root | |
if __name__ == '__main__': | |
TestSlider().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Needed this so much.