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, fit_mode="contain")
carousel.add_widget(image)
return carousel
CarouselApp().run()
Kv Example:
Carousel:
direction: 'right'
AsyncImage:
source: 'http://placehold.it/480x270.png&text=slide-1.png'
AsyncImage:
source: 'http://placehold.it/480x270.png&text=slide-2.png'
AsyncImage:
source: 'http://placehold.it/480x270.png&text=slide-3.png'
AsyncImage:
source: 'http://placehold.it/480x270.png&text=slide-4.png'
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)¶
Bases:
kivy.uix.stencilview.StencilViewCarousel class. See module documentation for more information.
- add_widget(widget, index=0, *args, **kwargs)¶
Add a new widget as a child of this widget.
- Parameters:
- widget:
Widget Widget to add to our list of children.
- index: int, defaults to 0
Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.
New in version 1.0.5.
- canvas: str, defaults to None
Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.
New in version 1.9.0.
- widget:
>>> from kivy.uix.button import Button >>> from kivy.uix.slider import Slider >>> root = Widget() >>> root.add_widget(Button()) >>> slider = Slider() >>> root.add_widget(slider)
- clear_widgets(children=None, *args, **kwargs)¶
Remove all (or the specified)
childrenof this widget. If the ‘children’ argument is specified, it should be a list (or filtered list) of children of the current widget.Changed in version 1.8.0: The children argument can be used to specify the children you want to remove.
Changed in version 2.1.0: Specifying an empty
childrenlist leaves the widgets unchanged. Previously it was treated likeNoneand all children were removed.
- load_next(mode='next')¶
Animate to the next slide.
New in version 1.7.0.
- load_previous()¶
Animate to the previous slide.
New in version 1.7.0.
- load_slide(slide)¶
Animate to the slide that is passed as the argument.
Changed in version 1.8.0.
- on_touch_down(touch)¶
Receive a touch down event.
- Parameters:
- touch:
MotionEventclass Touch received. The touch is in parent coordinates. See
relativelayoutfor a discussion on coordinate systems.
- touch:
- Returns:
bool If True, the dispatching of the touch event will stop. If False, the event will continue to be dispatched to the rest of the widget tree.
- on_touch_move(touch)¶
Receive a touch move event. The touch is in parent coordinates.
See
on_touch_down()for more information.
- on_touch_up(touch)¶
Receive a touch up event. The touch is in parent coordinates.
See
on_touch_down()for more information.
- remove_widget(widget, *args, **kwargs)¶
Remove a widget from the children of this widget.
- Parameters:
- widget:
Widget Widget to remove from our children list.
- widget:
>>> from kivy.uix.button import Button >>> root = Widget() >>> button = Button() >>> root.add_widget(button) >>> root.remove_widget(button)