Table Of Contents
Carousel¶
New in version 1.4.0.
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.
Example:
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
class CarouselApp(App):
def build(self):
carousel = Carousel(direction='right')
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
CarouselApp().run()
Changed in version 1.5.0: The carousel now supports active children, like the
ScrollView. It will detect a swipe gesture
according to the Carousel.scroll_timeout and
Carousel.scroll_distance properties.
In addition, the slide container is no longer exposed by the API.
The impacted properties are
Carousel.slides, Carousel.current_slide,
Carousel.previous_slide and Carousel.next_slide.
-
class
kivy.uix.carousel.Carousel(**kwargs)[source]¶ Bases:
kivy.uix.stencilview.StencilViewCarousel class. See module documentation for more information.
-
anim_cancel_duration¶ Defines the duration of the animation when a swipe movement is not accepted. This is generally when the user does not make a large enough swipe. See
min_move.anim_cancel_durationis aNumericPropertyand defaults to 0.3.
-
anim_move_duration¶ Defines the duration of the Carousel animation between pages.
anim_move_durationis aNumericPropertyand defaults to 0.5.
-
anim_type¶ Type of animation to use while animating to the next/previous slide. This should be the name of an
AnimationTransitionfunction.anim_typeis aStringPropertyand defaults to ‘out_quad’.New in version 1.8.0.
-
current_slide¶ The currently shown slide.
current_slideis anAliasProperty.Changed in version 1.5.0: The property no longer exposes the slides container. It returns the widget you have added.
-
direction¶ Specifies the direction in which the slides are ordered. This corresponds to the direction from which the user swipes to go from one slide to the next. It can be right, left, top, or bottom. For example, with the default value of right, the second slide is to the right of the first and the user would swipe from the right towards the left to get to the second slide.
directionis anOptionPropertyand defaults to ‘right’.
-
index¶ Get/Set the current slide based on the index.
indexis anAliasPropertyand defaults to 0 (the first item).
-
load_slide(slide)[source]¶ Animate to the slide that is passed as the argument.
Changed in version 1.8.0.
-
loop¶ Allow the Carousel to loop infinitely. If True, when the user tries to swipe beyond last page, it will return to the first. If False, it will remain on the last page.
loopis aBooleanPropertyand defaults to False.
-
min_move¶ Defines the minimum distance to be covered before the touch is considered a swipe gesture and the Carousel content changed. This is a percentage of the Carousel width. If the movement doesn’t reach this minimum value, then the movement is cancelled and the content is restored to its original position.
min_moveis aNumericPropertyand defaults to 0.2.
-
next_slide¶ The next slide in the Carousel. It is None if the current slide is the last slide in the Carousel. This ordering reflects the order in which the slides are added: their presentation varies according to the
directionproperty.next_slideis anAliasProperty.Changed in version 1.5.0: The property no longer exposes the slides container. It returns the widget you have added.
-
previous_slide¶ The previous slide in the Carousel. It is None if the current slide is the first slide in the Carousel. This ordering reflects the order in which the slides are added: their presentation varies according to the
directionproperty.previous_slideis anAliasProperty.Changed in version 1.5.0: This property no longer exposes the slides container. It returns the widget you have added.
-
scroll_distance¶ Distance to move before scrolling the
Carouselin pixels. As soon as the distance has been traveled, theCarouselwill start to scroll, and no touch event will go to children. It is advisable that you base this value on the dpi of your target device’s screen.scroll_distanceis aNumericPropertyand defaults to 20dp.New in version 1.5.0.
-
scroll_timeout¶ Timeout allowed to trigger the
scroll_distance, in milliseconds. If the user has not movedscroll_distancewithin the timeout, no scrolling will occur and the touch event will go to the children.scroll_timeoutis aNumericPropertyand defaults to 200 (milliseconds)New in version 1.5.0.
-
slides¶ List of slides inside the Carousel. The slides are the widgets added to the Carousel using the
add_widgetmethod.slidesis aListPropertyand is read-only.
-