Cannot Load images into Carousel

28 views
Skip to first unread message

rPhoenix

unread,
Feb 29, 2020, 1:52:00 PM2/29/20
to Kivy users support
Hello everyone,

I'm a newbie here and trying to do some basic stuff. I am trying to make a carousel of images from the same directory. All images are numbered in a sequence. I can load one image fine, but I can't have it run multiple, Not sure what I'm missing here. I tried looking but no luck. I just don't understand it.

Any help appreciated.


from kivy.app import App
from kivy.lang import Builder
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage

kv
= '''
Carousel:
    direction: '
right'
    AsyncImage:
        source: '
1a.PNG'
    AsyncImage:
        source: '
2a.PNG'
    AsyncImage:
        source: '
3a.PNG'
'''


class NewProjectApp(App):
   
def build(self):
        carousel
= Carousel(direction='right')
       
for i in range(4):
            src
= " %d a.PNG" % i
            image
= AsyncImage(source=src, allow_stretch=True)
            carousel
.add_widget(image)
       
return carousel

       
return Builder.load_string(kv)


NewProjectApp().run()


Elliot Garbus

unread,
Feb 29, 2020, 5:33:20 PM2/29/20
to kivy-...@googlegroups.com

Good news,  you are working too hard!

 

The code you put in build ‘overlaps’ with the code you have described in kv.  All you need to do is reduce most of the code in build.

For files that are local to your machine, you could simply use Image, rather than AsycImage.

 

Swipe right and you will see the next image.

 

from kivy.app import App
from kivy.lang import
Builder

kv =
'''

Carousel:
    direction: 'right'
    AsyncImage:
        source: '1a.PNG'
    AsyncImage:
        source: '2a.PNG'
    AsyncImage:
        source: '3a.PNG'
'''

class NewProjectApp(App):
   
def build(self):
       
return Builder.load_string(kv)


NewProjectApp().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8b694799-38e7-4b2f-9ec1-06a2236ad646%40googlegroups.com.

 

Elliot Garbus

unread,
Feb 29, 2020, 5:42:46 PM2/29/20
to kivy-...@googlegroups.com

Here is a version that automatically goes to the next slide every 4 seconds.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock

kv =
'''
Carousel:
    direction: 'right'
    loop: True

    AsyncImage:
        source: '1a.PNG'
    AsyncImage:
        source: '2a.PNG'
    AsyncImage:
        source: '3a.PNG'
'''


class NewProjectApp(App):
   
def build(self):
       
return Builder.load_string(kv)

   
def on_start(self):
        Clock.schedule_interval(
self.next_slide, 4)    # the number of seconds between slides...

   
def next_slide(self, dt):
       
self.root.load_next()


NewProjectApp().run()

 

 

From: rPhoenix
Sent: Saturday, February 29, 2020 11:52 AM
To: Kivy users support
Subject: [kivy-users] Cannot Load images into Carousel

 

Hello everyone,

--

Reply all
Reply to author
Forward
0 new messages