我想将Spinner中所选字符串值用于标签文本,但无法像以下代码中那样实现。请有人帮忙!!!
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
tex=' '
jj=0
super(LoginScreen, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text='Pressure (barg)',height=11 ))
self.username = TextInput(multiline=False, height=11)
self.add_widget(self.username)
self.add_widget(Label(text='Temperature (deg C)'))
self.password = TextInput(multiline=False, height=11)
self.add_widget(self.password)
spinner = Spinner(text='Select..', values=s, size_hint=(None, None))
def show_selected_value(spinner, text):
print('The spinner','have text', text)
jj=0
for j in range(0,852,1):
if b3112012[j][6]==text:
tex=text
jj=j+1
break
else:
pass
print('The index of selected is ', jj)
print(tex)
tex=text
print('Index is:', jj)
spinner.bind(text=show_selected_value)
self.add_widget(spinner)
#print('value' , show_selected_value)
dlabel=Label(text="%s" % str(spinner.text))
self.add_widget(dlabel)
第二个最后一行,即"dlabel=Label(text="%s"%str(spinner.text))
在程序运行时没有将所选的Spinner文本显示在dlabel文本中。我该如何获取Spinner索引或字符串值以在代码中使用?
show_selected_value
方法粘贴到了__init__
方法中间? - inclement