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 kivy.uix.boxlayout import BoxLayout

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

KV = '''
<Content>
    size_hint_y: None
    height: self.minimum_height

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

        IconLeftWidget:
            icon: 'phone'


ScrollView:

    GridLayout:
        id: box
        cols: 1
        size_hint_y: None
        height: self.minimum_height
'''


class Content(BoxLayout):
    '''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

Bases: kivymd.uix.list.OneLineAvatarIconListItem

Single line panel.

class kivymd.uix.expansionpanel.MDExpansionPanelTwoLine

Bases: kivymd.uix.list.TwoLineAvatarIconListItem

Two-line panel.

class kivymd.uix.expansionpanel.MDExpansionPanelThreeLine

Bases: kivymd.uix.list.ThreeLineAvatarIconListItem

Three-line panel.

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

Bases: kivy.uix.relativelayout.RelativeLayout

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)