Carousel widget in Kivy

Overview:

  • Kivy provides a Carousel widget, which enables traversing through a set of slides.

 

  • The slides in a Carousel could be images, videos or any other contents.

 

  • The contents of the Carousel can be either moved horizontally or vertically through swipes.

 

  • Carousel is a powerful way of representing an image gallery, video gallery, news articles and the like.

 

  • Carousels can be auto-played as an animation or it can be played manually through swipes.

 

  • Kivy provides several customizations to a Carousel that include:
  • Animation effect while transition is made from one slide to another slide, duration of the transition period
  • Specifying the direction of the swipe
  • Disabling vertical swipes
  • Whether the carousel should loop infinitely or not
  • Specification of minimum distance to be considered while accepting a swipe
  • Specification of minimum duration to be considered while accepting a swipe   
  • Specifying current, previous and next slides

 

Example:

from kivy.app import App

from kivy.uix.carousel import Carousel

from kivy.uix.image import AsyncImage

 

 

class CarouselDemo(App):

    

     def build(self):

          carouselObject = Carousel(direction='left')

 

          for i in range(4):

               imageFile = "./%d.jpg" % i

               asyncImageObject = AsyncImage(source = imageFile)

    

               carouselObject.add_widget(asyncImageObject)

         

          carouselObject.index = 2

          return carouselObject

         

# Start the Carousel App

if __name__ == '__main__':

     CarouselDemo().run()

 

Output:

Carousel widget in Kivy - Example


Copyright 2024 © pythontic.com