【发布时间】:2013-11-05 19:10:12
【问题描述】:
我阅读了this 和that 标签。 我的函数回调有错误,标签有 NoneType。
class Root(FloatLayout):
def callback( self, label, instance, *args ):
## Try to pass Button.text to the label,
## but type(label) is a NoneType
label.text = instance.text # here
print(label, type(label))
def load_content(self):
content = self.content
for but in range(65, 67):
content.add_widget(Button( text=chr(but),
on_press = partial(self.callback, self.lbl),
font_size=20 ))
content = ObjectProperty(None)
lbl = ObjectProperty(None)
【问题讨论】:
-
lbl 是否在您的 .kv 文件中定义为根定义的一部分?
-
我搞错了。我在 Builder 的左侧声明了
label,但从右侧调用了lbl。<Root> label: lbl Label: id: lbl ...