Introduction
Kivy is a Python GUI tool that works on any platform. It can operate on Android, iOS, Linux, and Windows, among other platforms. It is mostly used to create Android applications, but it may also be used to create desktop applications.
Carousel Widget In Kivy
The Carousel widget provides a mobile-friendly carousel layout that allows you to swipe between slides. Any material may be added to the carousel, and it can move horizontally or vertically. The carousel can display pages in a loop or in a series.
Important Points to Keep in Mind:
1. It makes it simple to navigate a series of slides.
2. It can store images, movies, and other types of material.
3. Swipes can be vertical or horizontal in nature.
4. A Carousel can be customised in a number of ways with Kivy, including:
4.1 While transitioning from one slide to the next, the animation effect is used, as
well as the duration of the transition phase.
4.2 Specifying the swipe's direction.
4.3 Vertical swipes are disabled.
4.4 Whether or whether the carousel should loop indefinitely
4.5 Minimum distance to consider when accepting a swipe is specified.
4.6 Minimum length to be taken into account when accepting a swipe
4.7 Choosing the current, previous, and following slides.
Program Implementation
# importing App class from kivy.app
from kivy.app import App
# importing Crousel class from kivy's
# UI feature carousel
from kivy.uix.carousel import Carousel
# importing AsyncImage class from kivy's
# UI image to handle asyncronus network image
from kivy.uix.image import AsyncImage
# Inheriting the App and extending
# it functionality
class CarouselApp(App):
def build(self):
# 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
image = AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
# Run the app
if __name__ == '__main__':
CarouselApp().run()