Reputation: 507
Please forgive me I am in my infancy learning Python and started using Kivy not too long ago.
I am simply trying to add photos from my "carousel/" directory in my project to be each photo that comes up in the carousel app one by one when it loads.
The code runs fine, and I am even able to load Async photos with the link to the photo, but for whatever reason when I try to load photos from my "carousel" folder they don't show up.
I know that these photos return otherwise because I used the "Image" call and it worked, I also looked all over and there were other solutions but I could not make the connection between their solution and what it is I need.
Here is the code and a picture below, like I said the code builds and runs fine but the pictures won't show up. Thank you in advance!
[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]
https://i.sstatic.net/igyeq.png
Upvotes: 1
Views: 1045
Reputation: 16031
You have to store all your pictures in a folder called carousel, and you can remove the Factory.
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()
Upvotes: 2
Reputation: 2645
You are trying to load 'carousel/0.jpg'
and 'carousel/1.jpg'
instead of 'carousel_images/00.jpg'
and 'carousel_images/01.jpg'
, Try this:
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_images/0{}.jpg".format(str(i))
image = Factory.AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
CarouselApp().run()
Upvotes: 1