temp_label = Label(text= str(temp) + 'C', pos=(-300, -50))
temp_label.bind(on_touch_down = self.disappear)
self.add_widget(temp_label)
def disappear(self, label_instance, label_choice):
self.remove_widget(self.temp_label)
我想使用'on_touch_down'删除标签,但是每次我遇到此错误
AttributeError: 'UK_Weather' object has no attribute 'temp_label'
上面只是一段代码,如果可能的话,答案可能是python语言
答案 0 :(得分:0)
尝试更改;
temp_label = Label(text= str(temp) + 'C', pos=(-300, -50))
temp_label.bind(on_touch_down = self.disappear)
self.add_widget(temp_label)
至:;
self.temp_label = Label(text= str(temp) + 'C', pos=(-300, -50))
self.temp_label.bind(on_touch_down = self.disappear)
self.add_widget(self.temp_label)
否则未定义self.temp_label
(如错误消息所述)。