Expansion Panel

Expansion panels contain creation flows and allow lightweight editing of an element.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/expansion-panel.png

Usage

self.add_widget(
    MDExpansionPanel(
        icon="logo.png",  # panel icon
        content=Content(),  # panel content
        panel_cls=MDExpansionPanelOneLine(text="Secondary text"),  # panel class
    )
)

To use MDExpansionPanel you must pass one of the following classes to the panel_cls parameter:

These classes are inherited from the following classes:

self.root.ids.box.add_widget(
    MDExpansionPanel(
        icon="logo.png",
        content=Content(),
        panel_cls=MDExpansionPanelThreeLine(
            text="Text",
            secondary_text="Secondary text",
            tertiary_text="Tertiary text",
        )
    )
)

Example

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
from kivymd import images_path

KV = '''
<Content>
    adaptive_height: True

    TwoLineIconListItem:
        text: "(050)-123-45-67"
        secondary_text: "Mobile"

        IconLeftWidget:
            icon: 'phone'


ScrollView:

    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class Content(MDBoxLayout):
    '''Custom content.'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        for i in range(10):
            self.root.ids.box.add_widget(
                MDExpansionPanel(
                    icon=f"{images_path}kivymd_logo.png",
                    content=Content(),
                    panel_cls=MDExpansionPanelThreeLine(
                        text="Text",
                        secondary_text="Secondary text",
                        tertiary_text="Tertiary text",
                    )
                )
            )


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/expansion-panel.gif

Two events are available for MDExpansionPanel

MDExpansionPanel:
    on_open: app.on_panel_open(args)
    on_close: app.on_panel_close(args)

The user function takes one argument - the object of the panel:

def on_panel_open(self, instance_panel):
    print(instance_panel)

API - kivymd.uix.expansionpanel

class kivymd.uix.expansionpanel.MDExpansionPanelOneLine(**kwargs)

Single line panel.

class kivymd.uix.expansionpanel.MDExpansionPanelTwoLine(**kwargs)

Two-line panel.

class kivymd.uix.expansionpanel.MDExpansionPanelThreeLine(**kwargs)

Three-line panel.

class kivymd.uix.expansionpanel.MDExpansionPanel(**kwargs)
Events

on_open

Called when a panel is opened.

on_close

Called when a panel is closed.

content

Content of panel. Must be Kivy widget.

content is an ObjectProperty and defaults to None.

icon

Icon of panel.

icon is an StringProperty and defaults to ‘’.

opening_transition

The name of the animation transition type to use when animating to the state ‘open’.

opening_transition is a StringProperty and defaults to ‘out_cubic’.

opening_time

The time taken for the panel to slide to the state ‘open’.

opening_time is a NumericProperty and defaults to 0.2.

closing_transition

The name of the animation transition type to use when animating to the state ‘close’.

closing_transition is a StringProperty and defaults to ‘out_sine’.

closing_time

The time taken for the panel to slide to the state ‘close’.

closing_time is a NumericProperty and defaults to 0.2.

panel_cls

Panel object. The object must be one of the classes MDExpansionPanelOneLine, MDExpansionPanelTwoLine or MDExpansionPanelThreeLine.

panel_cls is a ObjectProperty and defaults to None.

on_open(self, *args)

Called when a panel is opened.

on_close(self, *args)

Called when a panel is closed.

check_open_panel(self, instance)

Called when you click on the panel. Called methods to open or close a panel.

set_chevron_down(self)

Sets the chevron down.

set_chevron_up(self, instance_chevron)

Sets the chevron up.

close_panel(self, instance_panel)

Method closes the panel.

open_panel(self, *args)

Method opens a panel.

add_widget(self, widget, index=0, canvas=None)

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)