Python | Carousel Widget In Kivy

06 Feb, 2020
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
 Kivy Tutorial – Learn Kivy with Examples.
The Carousel widget provides the classic mobile-friendly carousel view where you can swipe between slides. You can add any content to the carousel and have it move horizontally or vertically. The carousel can display pages in a sequence or a loop.
Some Important Points to notice:
1) It provides ease to traverse set of slides.2) It can hold image, videos or any other content3) The movement can be vertical or horizontal swipes4) Kivy provides several customizations to a Carousel that include:
Animation effect while a 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
To work with this widget you must have to import:
from kivy.uix.carousel import Carousel
Basic Approach:
1) import kivy
2) import kivy App
3) import Gridlayout
4) import widget
5) set minimum version(optional)
6) Create as much as widget class as needed
7) create the App class
8) return the widget/layout etc class
9) Run an instance of the class
Implementation of the Approach:
# Program to explain how to add carousel in kivy     # import kivy module    import kivy        # base Class of your App inherits from the App class.    # app:always refers to the instance of your application   from kivy.app import App     # this restrict the kivy version i.e  # below this kivy version you cannot  # use the app or software  kivy.require('1.9.0')     # The Image widget is used to display an image # this module contain all features of images from kivy.uix.image import AsyncImage  # The Carousel widget provides the# classic mobile-friendly carousel# view where you can swipe between slidesfrom kivy.uix.carousel import Carousel      # Create the App classclass CarouselApp(App):    def build(self):          # Add carousel        # And add the direction of swipe        carousel = Carousel(direction ='right')          # Adding 10 slides        for i in range(10):            src = "http://placehold.it / 480x270.png&text = slide-%d&.png" %i            # using Asynchronous image                        image = AsyncImage(source = src, allow_stretch = True)            carousel.add_widget(image)        return carousel  # Run the AppCarouselApp().run()
Output:
Python-gui
Python-kivy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
Iterate over a list in Python