Kivy Spinner: is any event triggered when a value is selected from the Spinner

点点圈 提交于 2019-12-23 09:55:49

问题


I introduce a Spinner in my widget, and I want to perform some action every time I chose a different value from it.

Is it possible?

I only seem to get events on_press and on_release, but they are not triggered when a choice for a different value is made :-(

Best regards,

Bojan


回答1:


Beacuse the spinner updates its text property every time attr:values are changes,
I would do someting 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)



回答2:


you have 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"


来源:https://stackoverflow.com/questions/31721385/kivy-spinner-is-any-event-triggered-when-a-value-is-selected-from-the-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!