from kivy.lang import Builder
from kivymd.uix.menu import MDDropdownMenu

from kivymd.app import MDApp

KV = '''
    md_bg_color: self.theme_cls.backgroundColor

        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.open_menu(self)

            id: drop_text
            text: "Item"

class Example(MDApp):
    def open_menu(self, item):
        menu_items = [
                "text": f"{i}",
                "on_release": lambda x=f"Item {i}": self.menu_callback(x),
            } for i in range(5)
        MDDropdownMenu(caller=item, items=menu_items).open()

    def menu_callback(self, text_item):
        self.root.ids.drop_text.text = text_item

    def build(self):
        return Builder.load_string(KV)


API break#

1.2.0 version#

    text: 'Item'
    on_release: print(*args)

2.0.0 version#

    on_release:  print(*args)

        text: "Item text"

API - kivymd.uix.dropdownitem.dropdownitem#

class kivymd.uix.dropdownitem.dropdownitem.MDDropDownItemText(*args, **kwargs)#

Base texture for MDDropDownItem class (item text).

For more information, see in the MDLabel class documentation.

New in version 2.0.0.

class kivymd.uix.dropdownitem.dropdownitem.MDDropDownItem(*args, **kwargs)#

Dropdown item class.

For more information, see in the DeclarativeBehavior and ThemableBehavior and ButtonBehavior and BoxLayout classes documentation.

add_widget(widget, *args, **kwargs)#

Add a new widget as a child of this widget.

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)
update_text_item(instance, value) None#

Updates the text of the item.

on_disabled(instance, value) None#

Fired when the values of disabled change.

on__drop_down_text(instance, value) None#

Fired when the values of _drop_down_text change.