Expansion Panel¶
Expansion panels contain creation flows and allow lightweight editing of an element.
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()
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.OneLineAvatarIconListItemSingle line panel.
-
class
kivymd.uix.expansionpanel.MDExpansionPanelTwoLine¶ Bases:
kivymd.uix.list.TwoLineAvatarIconListItemTwo-line panel.
-
class
kivymd.uix.expansionpanel.MDExpansionPanelThreeLine¶ Bases:
kivymd.uix.list.ThreeLineAvatarIconListItemThree-line panel.
-
class
kivymd.uix.expansionpanel.MDExpansionPanel(**kwargs)¶ Bases:
kivy.uix.relativelayout.RelativeLayout- Events
-
content¶ Content of panel. Must be Kivy widget.
contentis anObjectPropertyand defaults to None.
-
icon¶ Icon of panel.
iconis anStringPropertyand defaults to ‘’.
-
opening_transition¶ The name of the animation transition type to use when animating to the
state‘open’.opening_transitionis aStringPropertyand defaults to ‘out_cubic’.
-
opening_time¶ The time taken for the panel to slide to the
state‘open’.opening_timeis aNumericPropertyand defaults to 0.2.
-
closing_transition¶ The name of the animation transition type to use when animating to the
state‘close’.closing_transitionis aStringPropertyand defaults to ‘out_sine’.
-
closing_time¶ The time taken for the panel to slide to the
state‘close’.closing_timeis aNumericPropertyand defaults to 0.2.
-
panel_cls¶ Panel object. The object must be one of the classes
MDExpansionPanelOneLine,MDExpansionPanelTwoLineorMDExpansionPanelThreeLine.panel_clsis aObjectPropertyand 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)¶