How to select kivy old value for the spinner

Rather than using the on_text or on_select, you can use the Buttons that make up the DropDown to trigger whatever method you want to run. That way, it doesn’t matter whether the same Button is selected or not. Here is a simple example of that approach:

from kivy.app import App
from kivy.lang import Builder

kv = '''
#:import Factory kivy.factory.Factory

<[email protected]>:
    on_release: app.spinner_selected(self.text)

RelativeLayout:
    Spinner:
        text: 'Choose One'
        size_hint: 0.2, 0.2
        pos_hint: {'center_x':0.5, 'center_y':0.5}
        option_cls: Factory.get('MySpinnerOption')
        values: ['1', '2', '3']
        # on_text: app.spinner_selected(self.text)   # not needed
'''

class TestApp(App):
    def build(self):
        return Builder.load_string(kv)

    def spinner_selected(self, text):   # whatever method you want to run
        print('spinner selected:', text)

TestApp().run()

The above code sets the on_release of the Buttons in the DropDown of the Spinner to the method that you would normally assign using 'on_text. Now, that method will be called whenever one of the Buttons is released.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top