Carousel widget in Kivy

Carousel widget in Kivy implements a standard carousel of rotating slides with any kind of content like images, video and so on. An example carousel is provided.

Kivy Updated 9 May 2017 1 min read

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

python
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