Swiper#

#

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/mdswiper-preview.gif

Usage#

MDSwiper:

    MDSwiperItem:

    MDSwiperItem:

    MDSwiperItem:

Example#

from kivy.lang.builder import Builder

from kivymd.app import MDApp

kv = '''
<MySwiper@MDSwiperItem>

    FitImage:
        source: "bg.jpg"
        radius: [dp(20),]


MDScreen:
    md_bg_color: self.theme_cls.backgroundColor

    MDSwiper:
        size_hint_y: None
        height: root.height - dp(40)
        y: root.height - self.height - dp(20)

        MySwiper:

        MySwiper:

        MySwiper:

        MySwiper:

        MySwiper:
'''


class Main(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        return Builder.load_string(kv)


Main().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/swiper-example.gif

Warning

The width of MDSwiperItem is adjusted automatically. Consider changing that by width_mult.

Warning

The width of MDSwiper is automatically adjusted according to the width of the window.

MDSwiper provides the following events for use:

__events__ = (
    "on_swipe",
    "on_pre_swipe",
    "on_overswipe_right",
    "on_overswipe_left",
    "on_swipe_left",
    "on_swipe_right"
)
MDSwiper:
    on_swipe: print("on_swipe")
    on_pre_swipe: print("on_pre_swipe")
    on_overswipe_right: print("on_overswipe_right")
    on_overswipe_left: print("on_overswipe_left")
    on_swipe_left: print("on_swipe_left")
    on_swipe_right: print("on_swipe_right")

API - kivymd.uix.swiper.swiper#

class kivymd.uix.swiper.swiper.MDSwiperItem(*args, **kwargs)#

Swiper item class.

For more information, see in the MDBoxLayout class documentation.

class kivymd.uix.swiper.swiper.MDSwiper(*args, **kwargs)#

Swiper class.

For more information, see in the MDScrollView class documentation.

items_spacing#

The space between each MDSwiperItem.

items_spacing is an NumericProperty and defaults to 20dp.

transition_duration#

Duration of switching between MDSwiperItem.

transition_duration is an NumericProperty and defaults to 0.2.

size_duration#

Duration of changing the size of MDSwiperItem.

transition_duration is an NumericProperty and defaults to 0.2.

size_transition#

The type of animation used for changing the size of MDSwiperItem.

size_transition is an StringProperty and defaults to out_quad.

swipe_transition#

The type of animation used for swiping.

swipe_transition is an StringProperty and defaults to out_quad.

swipe_distance#

Distance to move before swiping the MDSwiperItem.

swipe_distance is an NumericProperty and defaults to 70dp.

width_mult#

This number is multiplied by items_spacing x2 and then subtracted from the width of window to specify the width of MDSwiperItem. So by decreasing the width_mult the width of MDSwiperItem increases and vice versa.

width_mult is an NumericProperty and defaults to 3.

swipe_on_scroll#

Wheter to swipe on mouse wheel scrolling or not.

swipe_on_scroll is an BooleanProperty and defaults to True.

add_widget(widget, index=0)#

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.

>>> from kivy.uix.button import Button
>>> from kivy.uix.slider import Slider
>>> root = Widget()
>>> root.add_widget(Button())
>>> slider = Slider()
>>> root.add_widget(slider)
remove_widget(widget)#

Remove a widget from the children of this widget.

Parameters:
widget: Widget

Widget to remove from our children list.

>>> from kivy.uix.button import Button
>>> root = Widget()
>>> button = Button()
>>> root.add_widget(button)
>>> root.remove_widget(button)
set_current(index)#

Switch to given MDSwiperItem index.

get_current_index()#

Returns the current MDSwiperItem index.

get_current_item()#

Returns the current MDSwiperItem instance.

get_items()#

Returns the list of MDSwiperItem children.

Note

Use get_items() to get the list of children instead of MDSwiper.children.

on_swipe()#
on_pre_swipe()#
on_overswipe_right()#
on_overswipe_left()#
on_swipe_left()#
on_swipe_right()#
swipe_left()#
swipe_right()#
on_scroll_start(touch, check_children=True)#
on_touch_down(touch)#

Receive a touch down event.

Parameters:
touch: MotionEvent class

Touch received. The touch is in parent coordinates. See relativelayout for a discussion on coordinate systems.

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_up(touch)#

Receive a touch up event. The touch is in parent coordinates.

See on_touch_down() for more information.