Kivy Spinner: Any event fired when a value is selected from the Spinner

I am typing Spinner

into my widget and I want to perform some action every time I select a different value from it.

Is it possible?

I seem to be getting events on_press

and on_release

, but they don't fire when a selection is made for a different value: - (

Respectfully,

Boyan

+5


source to share


3 answers


Since the spinner updates its text property every time the attr: values ​​change,
I would do something like this:

    Spinner:        
      text: '<select>'
      values: ['White', 'Yellow', 'Red', 'Green']
      on_text: root.on_spinner_select(self.text)

      



In Python code:

class RootWidget(BoxLayout):
  def on_spinner_select(self, text):
    print (text)

      

+3


source


you need to use on_text:

spinner:
       id: my_spinner
       values: ("Home", "bureau", "kitchen")
       on_text: if my_spinner.text == "Home": root.Home()
                elif my_spinner.text == "bureau": root.bureau()
                else: root.kitchen()

      



now in python:

def Home():
   "do your things"
def bureau():
   "do your things"
def kitchen():
   "do your things"

      

+1


source


In kv file:
Spinner:
    id: spinner_id
    values: ["First","Second","Third")
    on_text: root.getPlace(self.text)

in python file:
class Winner(BoxLayout):
   def getPlace(self,text):
       print "You got " + text +" place."

I'll go with Avi va answer

      

0


source







All Articles