External button code to get carousel image attribute...

Joined
Mar 5, 2025
Messages
6
Reaction score
0
Hi guys & gals...

So I have this code that populates my Carousel with images from the path....

Python Code snippet...
Python:
class EzLaunchScreen(Screen):     
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        img_path = ('D:\\Steven\Desktop\\Python App\\Images\\Carousel\\')
        # Funtion get images int carousel...
        layout = FloatLayout()
        self.background_image = Image(source='Images\launchScreen.png')
        carousel_widget = Carousel(direction ='right')
        for img_file in os.listdir(img_path):
            if img_file.endswith(('.png', '.jpg', '.jpeg')):
                img = Image(source=os.path.join(img_path, img_file))
                print(f"Adding image: {img_file}")
                carousel_widget.add_widget(img)       
        layout.add_widget(self.background_image)       
        layout.add_widget(carousel_widget)
        self.add_widget(layout)

And in string snippet I have the following...

Code:
BoxLayout:       
        # This is the carousel library of brands...
        Carousel:
            id: carousel_widget       
            direction: 'right'
            on_index: root.on_carousel_swipe()

I want a function that can be called to get the name of the image as I swipe on the carousel to be printed...
This is what i have that does not work...Do i need to bind this somewhere...

Python:
# Funtion get image name
    def on_carousel_swipe(carousel_widget, instance, value):
        current_image = carousel_widget.ids.carousel_widget.slides[int(value)]
        img_name = current_image.source.split('\\')[-1]
        img_name = img_name.split('.')[0]
        print (img_name)

Thus far for the past 5 days I have posted other queries in many other forums and sadly no responses received...

I'm hoping this forum is more forthcoming...
 

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,291
Messages
2,571,455
Members
48,132
Latest member
KatlynC08

Latest Threads

Top