gpt4 book ai didi

Python Kivy 并将本地照片添加到 Carousel

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:25 24 4
gpt4 key购买 nike

请原谅我,我刚刚开始学习 Python,不久前才开始使用 Kivy。

我只是尝试将项目中“carousel/”目录中的照片添加为加载时轮播应用程序中出现的每张照片。

代码运行良好,我什至可以使用照片链接加载异步照片,但无论出于何种原因,当我尝试从“轮播”文件夹加载照片时,它们都不会显示。

我知道这些照片会以其他方式返回,因为我使用了“图像”调用并且它有效,我也查看了所有内容,还有其他解决方案,但我无法在他们的解决方案和我需要的内容之间建立联系。

下面是代码和图片,就像我说的那样,代码构建并运行良好,但图片不会显示。预先感谢您!

[from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from kivy.core.image import Image
from kivy.factory import Factory


class CarouselApp(App):

def build(self):

carousel = Carousel(direction='right')

for i in range(0,2):
src = "carousel/%s.jpg" % str(i)
image = Factory.AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel

CarouselApp().run()][1]

/image/igyeq.png

最佳答案

您必须将所有图片存储在名为 carousel 的文件夹中,并且可以删除 Factory。

示例

main.py
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage


class CarouselApp(App):

def build(self):

carousel = Carousel(direction='right')

for i in range(0, 6):
src = "carousel/%s.png" % str(i)
image = AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel


CarouselApp().run()

输出

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

关于Python Kivy 并将本地照片添加到 Carousel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47188642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com