List#
See also Lists are continuous, vertical indexes of text or images. The class Due to the variety in sizes and controls in the Material Design spec,
this module suffers from a certain level of complexity to keep the widgets
compliant, flexible and performant. For this KivyMD provides list items that try to cover the most common usecases,
when those are insufficient, there’s a base class called KivyMD provides the following list items classes for use: These widgets will take other widgets that inherit from As the name implies, KivyMD provides base classes such as Allows the use of items with custom widgets on the left. It allows the use of elements with custom widgets on the left
and the right. When using the AvatarListItem and IconListItem classes, when an icon is clicked,
the event of this icon is triggered: You can disable the icon event using the WithoutTouch classes:
MDList
in combination with a BaseListItem
like
OneLineListItem
will create a list that expands as items are added to
it, working nicely with Kivy’s ScrollView
.BaseListItem
which you can use to create your own list items. This documentation will only
cover the provided ones, for custom implementations please refer to this
module’s source code.Text only ListItems#
ListItems with widget containers#
ILeftBody
,
ILeftBodyTouch
, IRightBody
or IRightBodyTouch
and
put them in their corresponding container.ILeftBody
and IRightBody
will signal
that the widget goes into the left or right container, respectively.ILeftBodyTouch
and IRightBodyTouch
do the same thing,
except these widgets will also receive touch events that occur within their
surfaces.ImageLeftWidget
,
ImageRightWidget
, IconRightWidget
, IconLeftWidget
,
based on the above classes.
Usage#
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem
KV = '''
MDScrollView:
MDList:
id: container
'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
def on_start(self):
for i in range(20):
self.root.ids.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
Example().run()
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return (
MDScrollView(
MDList(
id="container"
)
)
)
def on_start(self):
for i in range(20):
self.root.ids.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
Example().run()
Events of List#
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScrollView:
MDList:
OneLineAvatarIconListItem:
on_release: print("Click!")
IconLeftWidget:
icon: "github"
OneLineAvatarIconListItem:
on_release: print("Click 2!")
IconLeftWidget:
icon: "gitlab"
'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
Example().run()
from kivymd.app import MDApp
from kivymd.uix.scrollview import MDScrollView
from kivymd.uix.list import MDList, OneLineAvatarIconListItem, IconLeftWidget
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return (
MDScrollView(
MDList(
OneLineAvatarIconListItem(
IconLeftWidget(
icon="github"
),
on_release=lambda x: print("Click!")
),
OneLineAvatarIconListItem(
IconLeftWidget(
icon="gitlab"
),
on_release=lambda x: print("Click 2!")
),
)
)
)
Example().run()
OneLineListItem#
OneLineListItem:
text: "Single-line item"
TwoLineListItem#
TwoLineListItem:
text: "Two-line item"
secondary_text: "Secondary text here"
ThreeLineListItem#
ThreeLineListItem:
text: "Three-line item"
secondary_text: "This is a multi-line label where you can"
tertiary_text: "fit more text than usual"
OneLineAvatarListItem#
OneLineAvatarListItem:
text: "Single-line item with avatar"
ImageLeftWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
OneLineAvatarListItem(
ImageLeftWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
)
TwoLineAvatarListItem#
TwoLineAvatarListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
ImageLeftWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
OneLineAvatarListItem(
ImageLeftWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
)
ThreeLineAvatarListItem#
ThreeLineAvatarListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
ImageLeftWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
OneLineAvatarListItem(
ImageLeftWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
tertiary_text: "fit more text than usual"
)
OneLineRightIconListItem#
OneLineRightIconListItem:
text: "Single-line item with avatar"
ImageRightWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
OneLineRightIconListItem(
ImageRightWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
)
TwoLineRightIconListItem#
TwoLineRightIconListItem:
text: "Single-line item with avatar"
secondary_text: "Secondary text here"
ImageRightWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
TwoLineRightIconListItem(
ImageRightWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
)
ThreeLineRightIconListItem#
ThreeLineRightIconListItem:
text: "Single-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
ImageRightWidget:
source: "kivymd/images/logo/kivymd-icon-256.png"
ThreeLineRightIconListItem(
ImageRightWidget(
source="kivymd/images/logo/kivymd-icon-256.png"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
tertiary_text: "fit more text than usual",
)
OneLineIconListItem#
OneLineIconListItem:
text: "Single-line item with avatar"
IconLeftWidget:
icon: "language-python"
OneLineIconListItem(
IconLeftWidget(
icon="language-python"
),
text="Single-line item with avatar"
)
TwoLineIconListItem#
TwoLineIconListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
IconLeftWidget:
icon: "language-python"
TwoLineIconListItem(
IconLeftWidget(
icon="language-python"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here"
)
ThreeLineIconListItem#
ThreeLineIconListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
IconLeftWidget:
icon: "language-python"
ThreeLineIconListItem(
IconLeftWidget(
icon="language-python"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
tertiary_text: "fit more text than usual",
)
OneLineAvatarIconListItem#
OneLineAvatarIconListItem:
text: "One-line item with avatar"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
OneLineAvatarIconListItem(
IconLeftWidget(
icon="plus"
),
IconRightWidget(
icon="minus"
),
text="Single-line item with avatar",
)
TwoLineAvatarIconListItem#
TwoLineAvatarIconListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
TwoLineAvatarIconListItem(
IconLeftWidget(
icon="plus"
),
IconRightWidget(
icon="minus"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
)
ThreeLineAvatarIconListItem#
ThreeLineAvatarIconListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
ThreeLineAvatarIconListItem(
IconLeftWidget(
icon="plus"
),
IconRightWidget(
icon="minus"
),
text="Single-line item with avatar",
secondary_text: "Secondary text here",
tertiary_text: "fit more text than usual",
)
Custom list item#
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.icon_definitions import md_icons
KV = '''
<ListItemWithCheckbox>:
IconLeftWidget:
icon: root.icon
RightCheckbox:
MDScrollView:
MDList:
id: scroll
'''
class ListItemWithCheckbox(OneLineAvatarIconListItem):
'''Custom list item.'''
icon = StringProperty("android")
class RightCheckbox(IRightBodyTouch, MDCheckbox):
'''Custom right container.'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
def on_start(self):
icons = list(md_icons.keys())
for i in range(30):
self.root.ids.scroll.add_widget(
ListItemWithCheckbox(text=f"Item {i}", icon=icons[i])
)
Example().run()
from kivymd.app import MDApp
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.uix.scrollview import MDScrollView
from kivymd.uix.list import MDList
from kivymd.icon_definitions import md_icons
class RightCheckbox(IRightBodyTouch, MDCheckbox):
'''Custom right container.'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return (
MDScrollView(
MDList(
id="scroll"
)
)
)
def on_start(self):
icons = list(md_icons.keys())
for i in range(30):
self.root.ids.scroll.add_widget(
OneLineAvatarIconListItem(
IconLeftWidget(
icon=icons[i]
),
RightCheckbox(),
text=f"Item {i}",
)
)
Example().run()
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.list import IRightBodyTouch
KV = '''
OneLineAvatarIconListItem:
text: "One-line item with avatar"
on_size:
self.ids._right_container.width = container.width
self.ids._right_container.x = container.width
IconLeftWidget:
icon: "cog"
YourContainer:
id: container
MDIconButton:
icon: "minus"
MDIconButton:
icon: "plus"
'''
class YourContainer(IRightBodyTouch, MDBoxLayout):
adaptive_width = True
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
Example().run()
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.list import IRightBodyTouch
from kivymd.uix.button import MDIconButton
from kivymd.uix.list import OneLineAvatarIconListItem, IconLeftWidget
class YourContainer(IRightBodyTouch, MDBoxLayout):
adaptive_width = True
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return (
OneLineAvatarIconListItem(
IconLeftWidget(
icon="cog"
),
YourContainer(
MDIconButton(
icon="minus"
),
MDIconButton(
icon="plus"
),
id="container"
),
text="One-line item with avatar"
)
)
def on_start(self):
container = self.root.ids.container
self.root.ids._right_container.width = container.width
container.x = container.width
Example().run()
Behavior#
OneLineIconListItem:
text: "Single-line item with icon"
IconLeftWidget:
icon: "language-python"
OneLineIconListItem(
IconLeftWidget(
icon="language-python"
),
text="Single-line item with avatar",
)
OneLineIconListItem:
text: "Single-line item with icon"
IconLeftWidgetWithoutTouch:
icon: "language-python"
OneLineIconListItem(
IconLeftWidgetWithoutTouch(
icon="language-python"
),
text="Single-line item with avatar",
)
API - kivymd.uix.list.list
#
- class kivymd.uix.list.list.MDList(*args, **kwargs)#
ListItem container. Best used in conjunction with a
kivy.uix.ScrollView
.When adding (or removing) a widget, it will resize itself to fit its children, plus top and bottom paddings as described by the MD spec.
For more information, see in the
MDGridLayout
classes documentation.
- class kivymd.uix.list.list.BaseListItem(*args, **kwargs)#
Base class to all ListItems. Not supposed to be instantiated on its own.
For more information, see in the
DeclarativeBehavior
andThemableBehavior
andRectangularRippleBehavior
andButtonBehavior
andFloatLayout
classes documentation.- text#
Text shown in the first line.
text
is aStringProperty
and defaults to ‘’.
- text_color#
Text color in (r, g, b, a) or string format used if
theme_text_color
is set to ‘Custom’.text_color
is aColorProperty
and defaults to None.
- font_style#
Text font style. See font-definitions for more information.
font_style
is aStringProperty
and defaults to ‘Subtitle1’.
- theme_text_color#
The name of the color scheme for for the primary text.
theme_text_color
is aStringProperty
and defaults to ‘Primary’.
- secondary_text#
Text shown in the second line.
secondary_text
is aStringProperty
and defaults to ‘’.
- tertiary_text#
The text is displayed on the third line.
tertiary_text
is aStringProperty
and defaults to ‘’.
- secondary_text_color#
Text color in (r, g, b, a) or string format used for secondary text if
secondary_theme_text_color
is set to ‘Custom’.secondary_text_color
is aColorProperty
and defaults to None.
- tertiary_text_color#
Text color in (r, g, b, a) or string format used for tertiary text if
tertiary_theme_text_color
is set to ‘Custom’.tertiary_text_color
is aColorProperty
and defaults to None.
- secondary_theme_text_color#
The name of the color scheme for for the secondary text.
secondary_theme_text_color
is aStringProperty
and defaults to ‘Secondary’.
- tertiary_theme_text_color#
The name of the color scheme for for the tertiary text.
tertiary_theme_text_color
is aStringProperty
and defaults to ‘Secondary’.
- secondary_font_style#
Font style for secondary line. See font-definitions for more information.
secondary_font_style
is aStringProperty
and defaults to ‘Body1’.
- tertiary_font_style#
Font style for tertiary line. See font-definitions for more information.
tertiary_font_style
is aStringProperty
and defaults to ‘Body1’.
- divider#
Divider mode. Available options are: ‘Full’, ‘Inset’ and default to ‘Full’.
divider
is aOptionProperty
and defaults to ‘Full’.
- divider_color#
Divider color in (r, g, b, a) or string format.
New in version 1.0.0.
divider_color
is aColorProperty
and defaults to None.
- bg_color#
Background color for list item in (r, g, b, a) or string format.
bg_color
is aColorProperty
and defaults to None.
- radius#
Canvas radius.
# Top left corner slice. MDBoxLayout: md_bg_color: app.theme_cls.primary_color radius: [25, 0, 0, 0]
radius
is anVariableListProperty
and defaults to [0, 0, 0, 0].
- on_touch_down(self, 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.
- touch:
- 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_move(self, touch, *args)#
Receive a touch move event. The touch is in parent coordinates.
See
on_touch_down()
for more information.
- on_touch_up(self, touch)#
Receive a touch up event. The touch is in parent coordinates.
See
on_touch_down()
for more information.
- propagate_touch_to_touchable_widgets(self, touch, touch_event, *args)#
- add_widget(self, widget)#
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)
- remove_widget(self, widget)#
Remove a widget from the children of this widget.
- Parameters:
- widget:
Widget
Widget to remove from our children list.
- widget:
>>> from kivy.uix.button import Button >>> root = Widget() >>> button = Button() >>> root.add_widget(button) >>> root.remove_widget(button)
- class kivymd.uix.list.list.ILeftBodyTouch#
Same as
ILeftBody
, but allows the widget to receive touch events instead of triggering the ListItem’s ripple effect.
- class kivymd.uix.list.list.IRightBodyTouch#
Same as
IRightBody
, but allows the widget to receive touch events instead of triggering theListItem
’s ripple effect
- class kivymd.uix.list.list.OneLineListItem(*args, **kwargs)#
A one line list item.
For more information, see in the
BaseListItem
classes documentation.
- class kivymd.uix.list.list.TwoLineListItem(**kwargs)#
A two line list item.
For more information, see in the
BaseListItem
classes documentation.
- class kivymd.uix.list.list.ThreeLineListItem(*args, **kwargs)#
A three line list item.
For more information, see in the
BaseListItem
classes documentation.
- class kivymd.uix.list.list.OneLineAvatarListItem(*args, **kwargs)#
A one line list item with left image.
For more information, see in the
BaseListItem
classes documentation.
- class kivymd.uix.list.list.TwoLineAvatarListItem(*args, **kwargs)#
A two line list item with left image.
For more information, see in the
OneLineAvatarListItem
classes documentation.
- class kivymd.uix.list.list.ThreeLineAvatarListItem(*args, **kwargs)#
A three line list item with left image.
For more information, see in the
ThreeLineListItem
classes documentation.
- class kivymd.uix.list.list.OneLineIconListItem(*args, **kwargs)#
A one line list item with left icon.
For more information, see in the
OneLineListItem
classes documentation.
- class kivymd.uix.list.list.TwoLineIconListItem(*args, **kwargs)#
A two line list item with left icon.
For more information, see in the
OneLineIconListItem
classes documentation.
- class kivymd.uix.list.list.ThreeLineIconListItem(*args, **kwargs)#
A three line list item with left icon.
For more information, see in the
ThreeLineListItem
classes documentation.
- class kivymd.uix.list.list.OneLineRightIconListItem(*args, **kwargs)#
A one line list item with right icon/image.
For more information, see in the
OneLineListItem
classes documentation.
- class kivymd.uix.list.list.TwoLineRightIconListItem(**kwargs)#
A two line list item with right icon/image.
For more information, see in the
OneLineRightIconListItem
classes documentation.
- class kivymd.uix.list.list.ThreeLineRightIconListItem(**kwargs)#
A three line list item with right icon/image.
For more information, see in the
ThreeLineRightIconListItem
classes documentation.
- class kivymd.uix.list.list.OneLineAvatarIconListItem(*args, **kwargs)#
A one line list item with left/right icon/image/widget.
For more information, see in the
OneLineAvatarListItem
classes documentation.
- class kivymd.uix.list.list.TwoLineAvatarIconListItem(*args, **kwargs)#
A two line list item with left/right icon/image/widget.
For more information, see in the
TwoLineAvatarListItem
classes documentation.
- class kivymd.uix.list.list.ThreeLineAvatarIconListItem(*args, **kwargs)#
A three line list item with left/right icon/image/widget.
For more information, see in the
ThreeLineAvatarListItem
classes documentation.
- class kivymd.uix.list.list.ImageLeftWidget(**kwargs)#
The widget implements the left image for use in ListItem classes.
For more information, see in the
CircularRippleBehavior
andButtonBehavior
andILeftBodyTouch
andFitImage
classes documentation.
- class kivymd.uix.list.list.ImageLeftWidgetWithoutTouch(**kwargs)#
Disables the image event. The widget implements the left image for use in ListItem classes.
For more information, see in the
CircularRippleBehavior
andTouchBehavior
andButtonBehavior
andILeftBody
andFitImage
classes documentation.New in version 1.0.0.
- class kivymd.uix.list.list.ImageRightWidget(**kwargs)#
The widget implements the right image for use in ListItem classes.
For more information, see in the
CircularRippleBehavior
andButtonBehavior
andIRightBodyTouch
andFitImage
classes documentation.
- class kivymd.uix.list.list.ImageRightWidgetWithoutTouch(**kwargs)#
Disables the image event. The widget implements the right image for use in ListItem classes.
For more information, see in the
CircularRippleBehavior
andTouchBehavior
andButtonBehavior
andIRightBody
andFitImage
classes documentation.New in version 1.0.0.
- class kivymd.uix.list.list.IconRightWidget(*args, **kwargs)#
The widget implements the right icon for use in ListItem classes.
For more information, see in the
IRightBodyTouch
andMDIconButton
classes documentation.- pos_hint#
- class kivymd.uix.list.list.IconRightWidgetWithoutTouch(*args, **kwargs)#
Disables the icon event. The widget implements the right icon for use in ListItem classes.
For more information, see in the
TouchBehavior
andIRightBody
andMDIconButton
classes documentation.New in version 1.0.0.
- pos_hint#
- class kivymd.uix.list.list.IconLeftWidget(*args, **kwargs)#
The widget implements the left icon for use in ListItem classes.
For more information, see in the
ILeftBodyTouch
andMDIconButton
classes documentation.- pos_hint#
- class kivymd.uix.list.list.IconLeftWidgetWithoutTouch(*args, **kwargs)#
Disables the icon event. The widget implements the left icon for use in ListItem classes.
For more information, see in the
TouchBehavior
andILeftBody
andMDIconButton
classes documentation.New in version 1.0.0.
- pos_hint#
- class kivymd.uix.list.list.CheckboxLeftWidget(**kwargs)#
The widget implements the left checkbox element for use in ListItem classes.
For more information, see in the
ILeftBodyTouch
andMDCheckbox
classes documentation.