【问题标题】:removing labels in kivy去除kivy中的标签
【发布时间】:2020-08-03 21:55:19
【问题描述】:
     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'

以上只是sn-p的代码,如果可能的话可以用python语言回答

【问题讨论】:

    标签: python kivy label


    【解决方案1】:

    尝试改变;

    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 未定义(如错误消息所述)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 2013-08-17
      • 2017-09-21
      相关资源
      最近更新 更多