Add Images to Carousel via loop in KV file...

Joined
Mar 5, 2025
Messages
3
Reaction score
0
I know that one can add images like this...

Code:
def build(self):
        carrusel = Carousel(direction='bottom')

        for n in range(1, 15):
            src = f"roxxane/{n}.jpg"
            image = AsyncImage(source=src, allow_stretch=True)
            carrusel.add_widget(image)

or kv string like this...

Code:
Carousel:
            direction: 'right'         
            Image:
                source: 'Images\Carousel\Jose-Cuervo.png'
            Image:
                 source: 'Images\Carousel\Absolut.png'

But how can I do this loop in the kv code syntax...instead of images one below the other...

I tried a function but not sure how to call this function in the kv file...

Code:
class Tester(App):
    def build(self):
        scr = Builder.load_string(Code)
        return scr
    def add_Img(self, *args):
        box = self.root.ids.box
        for i in range(2):
            str = 'Images\Carousel\{i}.png'
            box.add_widget(str(i))

CrossPosted HERE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,289
Messages
2,571,435
Members
48,121
Latest member
ColinHibne

Latest Threads

Top