【发布时间】:2019-01-10 04:26:27
【问题描述】:
我在一个文件中创建了一些经典的 Python3 函数,使用字典作为参数。我想将此文件用作库,并使用 kivy 小部件中的功能。 所以这就是我的代码的作用:
#all kivy imports
import myLib
class MyGame(Widget):
myDict = DictProperty({1:0, 2:0, 3:0})
def addStuff(self, id):
self.myDict[id]+= 1
def myNotWorkingFunction(self):
number = myLib.getNumberFromDict(self.myDict)
self.text = "The result is "+str(number)
它不是那样工作的。如果我不使用myLib.getNumberFromDict,而设置number = 3,就可以了。
myLib.getNumberFromDict 与 python dict 配合得很好,因为我在尝试制作 kivy 应用程序之前使用了它。
我在 kivy 日志中有这个:
stderr: Exception KeyError: ('', ) in 'kivy.properties.observable_dict_dispatch' ignored
【问题讨论】:
标签: python python-3.x dictionary properties kivy