我正在使用kivy + phyton开发IOS和Androdi的数字目录,但是我不知道如何为这种情况重新加载图像。

在main.py上

class Pgrid(Screen):
   _ImagenFavorito = str

   def get_ImgFavorito(self, arg):
      img = arg
      for i in range(len(Heart_Array)):
        if Heart_Array[i][0] == img and Heart_Array[i][1] == 0:
            return 'data/icons/black/heart_empty_icon&16.png'
        else:
            if Heart_Array[i][0] == img and Heart_Array[i][1] == 1:
                return 'data/icons/black/heart_icon&16.png'

def update_corazon(self, picid):
    #lg = picid
    for i in range(len(Heart_Array)):
        if Heart_Array[i][0] == picid:
            Heart_Array[i][1] = 1
            return 'data/icons/black/heart_icon&16.png'
pass


.kv文件

<Pgrid>:
   BoxLayout:
      orientation: 'vertical'
      canvas.before:
        Color:
            rgb: .9, .9, .9
       Rectangle:
            size: self.size
            source: 'data/background_lite.png'
    BoxLayout:
        GridLayout:
            rows: 3
            colds: 4
            spacing: 10
            padding: 10, 10

            #GRID 1.1
            GridLayout:
                rows: 2
                clods: 1
                Image:
                    id: pic11
                    source: 'data/products/camabe.jpg'
                BoxLayout:
                    size_hint:1, 0.1
                    canvas.before:
                        Color:
                            rgba: 0, 0, 0, 0
                        Rectangle:
                            size: self.size
                            pos: self.pos
                    ImageButton:
                        id: 11
                        source: root.get_ImgFavorito(11)
                        #size_hint: .2, .2
                        pos_hint: {'center_y': 0.50, 'center_x': 0.50}
                        on_press: root.update_corazon(11)


当我运行并单击ImageButton时,调用roo.update_corazon(11)并更新Heart_Array,但我不知道如何重新加载此ImageButton的源。

任何想法?
提前致谢



在我的.py文件中,我更改为:

 def update_corazon(self, picid):
    for i in range(len(Heart_Array)):
        if Heart_Array[i][0] == picid:
            Heart_Array[i][1] = 1
            self.manager.current = 'pgrid'


现在我认为self.manager.current ='pgrid'将被重新加载Pgrid屏幕,但是不重新加载屏幕:(

最佳答案

最终,我改变了很多类似的事情,现在一切正常:

self.remove_widget(Pgrid(name='pgrid'))
self.add_widget(Pgrid(name='pgrid'))


并且仅在.kv上-> on_press: root.update_corazon(xx)

关于python - 如何在Kivy + Python上重新加载图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53389802/

10-14 17:44