【发布时间】:2015-07-12 19:45:35
【问题描述】:
通常微调器小部件会返回选定的文本。在我的应用程序中,我计划使用一些非标准字母(如:ü、ö、è)作为填充微调器的值。 下面的示例适用于我的 windows 机器,但我希望避免处理任何非 ASCII 字符以防止其他操作系统出现问题。
有没有办法不使用 list.index(text) 方法直接访问微调器选择的索引?
# This Python file uses the following encoding: utf-8
from kivy.base import runTouchApp
from kivy.uix.spinner import Spinner
spinnervalues = ['one_ö','two_ü','three_ä']
spinner = Spinner(
# default value shown
text='Home',
# available values
values=spinnervalues,
# just for positioning in our example
size_hint=(None, None),
size=(100, 44),
pos_hint={'center_x': .5, 'center_y': .5})
def show_selected_value(spinner, text):
print('The spinner', spinner, 'have text', text)
list_index = spinnervalues.index(text)
print('This list item index:', list_index)
spinner.bind(text=show_selected_value)
runTouchApp(spinner)
我尝试过类似的方法:
spinner.bind(index=show_selected_value)
但没有成功。
【问题讨论】:
-
Python 应该跨不同操作系统一致地处理 unicode。
-
感谢您的快速回复。看来我可以专注于其他问题了。