我正在使用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屏幕,但不要重新加载屏幕:(
答案 0 :(得分:0)
最后,我更改了很多类似的东西,现在一切正常:
self.remove_widget(Pgrid(name='pgrid'))
self.add_widget(Pgrid(name='pgrid'))
并且仅在.kv上-> on_press: root.update_corazon(xx)