从kivy下拉窗口小部件中检索值 [英] Retrieving values from a kivy dropdown widget
问题描述
我将如何从下拉列表中检索选定的项目?这是我到目前为止所拥有的.
How would I go about retrieving a selected item from the dropdown? Here is what I have so far.
这是kv文件:
<User_Interface>:
FloatLayout:
Spinner:
size_hint: .1,.1
pos_hint: {"x":0,"top":1.}
pos: 10,10
id: spinner_id
text: '<select>'
values: root.buildLists()
这是python文件:
And here is the python file:
class User_Interface(FloatLayout):
def buildLists(self):
list = self.ids.spinner_id.values = list[ 'A','B','C']
return list
例如,如果我选择A,我想将其返回给方法...
So for instance if I select A I would like to return it to a method...
我希望这是有道理的.
I hope it makes sense.
任何帮助将不胜感激.
Any help would be greatly appreciated.
推荐答案
您应将文本事件绑定到类中的方法.例如:
You should bind the text event to a method in the class. for example:
在您的kv文件中,为您的微调器设置一个ID,例如:
in your kv file set an id to your spinner like:
id: spin
在您将python代码输入到User_Interface类的 init 方法中后,您可以输入以下内容:
In you python code into the init method of your User_Interface class you can put something like this:
self.ids.spin.bind(text=showmethetext)
然后,在您的类中定义方法shomethetext
,例如:
Then, in your class define the method shomethetext
like:
def showmethetext(self, text):
print text
瞧!我猜应该可以.
再见
这篇关于从kivy下拉窗口小部件中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!