79254327

Date: 2024-12-05 10:49:54
Score: 0.5
Natty:
Report link

This question stemmed from me looking in the wrong place. I'm leaving it below for someone to meet their needs (just in case).

from kivy.lang import Builder
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu

KV = '''
MDScreen:

   MDRaisedButton:
       id: button
       text: "Press me"
       pos_hint: {"center_x": .5, "center_y": .5}
       on_release: app.menu_open()
'''


class Test(MDApp):
   def menu_open(self):
       menu_items = [
           {
               "text": f"Item {i}",
               "on_release": lambda x=f"Item {i}": self.menu_callback(x),
           } for i in range(5)
       ]
       MDDropdownMenu(
           caller=self.root.ids.button, items=menu_items
       ).open()

   def menu_callback(self, text_item):
       print(text_item)

   def build(self):
       self.theme_cls.primary_palette = "Orange"
       self.theme_cls.theme_style = "Dark"
       return Builder.load_string(KV)


Test().run()

More detailed data is in the documentation: enter link description here

Reasons:
  • Blacklisted phrase (0.5): enter link description here
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Ysmaýyl