我完全被难住了。我正在使用 .py 文件中的列表填充 .kv 文件中的值属性。
.kv文件
Spinner:
id: Mix_ingredient_1_spiner
size_hint: None, None
size: 200, 30
background_normal : ''
background_color: [.6549, 1, 1, 1]
text: "pick your ingredient"
values: root.i_list
on_text: root.print_Ingredient_list()
on_press:root.print_Ingredient_list()
.py 文件
class Product_1_Mix(Screen):
i_list = copy.deepcopy(config.ingredient_name_list)
# i_list = ["eggs", "milk", "flour", "sugar", "bad Chocolate"]
def print_Ingredient_list(self):
Product_1_Mix.i_list = copy.deepcopy(config.ingredient_name_list)
print(config.ingredient_name_list)
print(Product_1_Mix.i_list)
当我取消注释 i_list 和硬编码时,列表填充正常。当我使用 i_list 设置为配置文件中的列表时,列表中没有任何内容。
我使用 root.print_Ingredient_list() 进行调试,使用配置列表填充微调器值我得到这个:
['牛奶'、'糖'、'面粉'、'苹果'、'卡梅尔'、'巧克力'] ['牛奶'、'糖'、'面粉'、'苹果'、'卡梅尔'、'巧克力']
哪个是配置文件中的正确列表。 这表明 i_list 正确地从配置文件列表中获取值。 但它没有填充微调器。
怎么回事?!?
当我只在 def print_Ingredient_list(self) 之外设置 i_list 时:我明白了:
['牛奶'、'糖'、'面粉'、'苹果'、'卡梅尔'、'巧克力'] []