ExpansionPanel#
Expansion panels contain creation flows and allow lightweight editing of an element. To use These classes are inherited from the following classes: The user function takes one argument - the object of the panel:
Usage#
self.add_widget(
MDExpansionPanel(
icon="logo.png", # panel icon
content=Content(), # panel content
panel_cls=MDExpansionPanelOneLine(text="Secondary text"), # panel class
)
)
MDExpansionPanel
you must pass one of the following classes
to the panel_cls
parameter:
OneLineAvatarIconListItem
TwoLineAvatarIconListItem
ThreeLineAvatarIconListItem
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#
import os
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'
MDScrollView:
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=os.path.join(images_path, "logo", "kivymd-icon-128.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)
def on_panel_open(self, instance_panel):
print(instance_panel)
API - kivymd.uix.expansionpanel.expansionpanel
#
- class kivymd.uix.expansionpanel.expansionpanel.MDExpansionPanelOneLine(*args, **kwargs)#
Single line panel.
- class kivymd.uix.expansionpanel.expansionpanel.MDExpansionPanelTwoLine(*args, **kwargs)#
Two-line panel.
- class kivymd.uix.expansionpanel.expansionpanel.MDExpansionPanelThreeLine(*args, **kwargs)#
Three-line panel.
- class kivymd.uix.expansionpanel.expansionpanel.MDExpansionPanelLabel(**kwargs)#
Label panel.
- ..warning:: This class is created for use in the
MDStepperVertical
andMDStepper
classes, and has not been tested for use outside of these classes.
- class kivymd.uix.expansionpanel.expansionpanel.MDExpansionPanel(**kwargs)#
- Events:
- content#
Content of panel. Must be Kivy widget.
content
is anObjectProperty
and defaults to None.
- icon#
Icon of panel.
Icon Should be either be a path to an image or a logo name in
md_icons
icon
is anStringProperty
and defaults to ‘’.
- opening_transition#
The name of the animation transition type to use when animating to the
state
‘open’.opening_transition
is aStringProperty
and defaults to ‘out_cubic’.
- opening_time#
The time taken for the panel to slide to the
state
‘open’.opening_time
is aNumericProperty
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 aStringProperty
and defaults to ‘out_sine’.
- closing_time#
The time taken for the panel to slide to the
state
‘close’.closing_time
is aNumericProperty
and defaults to 0.2.
- panel_cls#
Panel object. The object must be one of the classes
MDExpansionPanelOneLine
,MDExpansionPanelTwoLine
orMDExpansionPanelThreeLine
.panel_cls
is aObjectProperty
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_panel: [MDExpansionPanelThreeLine, MDExpansionPanelTwoLine, MDExpansionPanelThreeLine, MDExpansionPanelLabel])#
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: MDExpansionChevronRight)#
Sets the chevron up.
- open_panel(self, *args)#
Method opens a panel.
- get_state(self)#
Returns the state of panel. Can be close or open .
- 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.
- 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)