如何在Kivy + Python上重新加载图像

问题描述 投票:1回答:1

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

在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屏幕但不重新加载屏幕:(

python image kivy reload
1个回答
0
投票

最后,我改变了很多这样的事情,现在所有工作:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.