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()
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.
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,
--