Kivy spinner on_text_changed event

You just need to use bind to trigger the spinner_text_changed() method when the text property changes, like this:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.spinner import Spinner

class MyApp(App):
    def build(self):

        mainbox = BoxLayout(orientation="horizontal",
                            spacing=15,
                            padding=5)
        self.spinner_languages = Spinner(text ="",
                values =("Python", "Java", "C++", "C", "C#", "PHP"),
                size_hint = (0.3, 0.2)
                )
        self.spinner_languages.bind(text=self.spinner_text_changed)
        mainbox.add_widget(self.spinner_languages)

        return mainbox

    def spinner_text_changed(self, spinner, text):
       self.language = text
       print(self.language)

if __name__ == "__main__":
    MyApp().run()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top