读取kv图片来源

时间:2016-02-04 03:03:36

标签: python kivy

我正在尝试使用kv语言显示从其他网站提取的图像('iphoto')。我收到一个错误,图像文件无法读取,但我可以从错误中复制图像地址,并在浏览器中提取图像没有问题。我做错了什么?

的信息:

Python 3.4

Kivy 1.9.1

Pertinent Python:('pet_photo'是从xml SOAP响应中提取的http地址)

class ScrollerApp(App):
    for child in root.iter('pet_id'):
        iphoto = child.find('pet_photo').text
    def build(self):
        self.load_kv('Scroller.kv')
        return TheBox()

if __name__ == '__main__':
    Window.fullscreen = 'auto'
    ScrollerApp().run() 

相关kv:

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}         
            Image:
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source: str(app.iphoto)

错误:

  

[错误] [图像]读取文件http://sms.petpoint.com/sms/photos/615/ba451ef8-3dd5-428f-b437-cca6521024d0.jpg

时出错

1 个答案:

答案 0 :(得分:1)

尝试使用AsyncImage。 AsyncImage Docs

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}         
            AsyncImage:
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source: str(app.iphoto)