python - 去除kivy中的标签
问题描述
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语言吗
解决方案
尝试改变;
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
未定义(如错误消息所述)。
推荐阅读
- events - 如何从存储在主结构中的回调调用 self 函数?
- pdf-generation - 无法访问 zabbix pdf 生成器
- c++ - 为 CNG 加密创建 IV
- spring - 如何在 Spring Boot 中获取所有已保存的帖子?
- javascript - 通过 HTTP 而不是 HTTPs 提供的 API 调用会导致 React/Axios 中的错误
- jestjs - 为什么永远不会调用第二个 Jest 模拟函数?
- typescript - 取消可观察对象中的 fetch 方法
- r - R中的ifelse函数用法
- c++ - 如何在一个代码文件中使用 CPLEX Concert 解决多个数学模型?
- python - 如果游戏运行中的条件为真,则何时应为假。(Python)