Menu¶
See also
Example¶
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.theming import ThemeManager
from kivymd.toast import toast
Builder.load_string('''
# Here a compulsory import
#:import MDDropdownMenu kivymd.uix.menu.MDDropdownMenu
<Menu@Screen>
MDRaisedButton:
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'Open menu'
opposite_colors: True
pos_hint: {'center_x': .2, 'center_y': .9}
on_release: MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
MDRaisedButton:
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'Open menu'
opposite_colors: True
pos_hint: {'center_x': .2, 'center_y': .1}
on_release:
MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
MDRaisedButton:
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'Open menu'
opposite_colors: True
pos_hint: {'center_x': .8, 'center_y': .1}
on_release: MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
MDRaisedButton:
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'Open menu'
opposite_colors: True
pos_hint: {'center_x': .8, 'center_y': .9}
on_release: MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
MDRaisedButton:
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'Open menu'
opposite_colors: True
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: MDDropdownMenu(items=app.menu_items, width_mult=4).open(self)
''')
class Test(MDApp):
menu_items = []
def callback_for_menu_items(self, *args):
toast(args[0])
def build(self):
self.menu_items = [
{
"viewclass": "MDMenuItem",
"text": "Example item %d" % i,
"callback": self.callback_for_menu_items,
}
for i in range(15)
]
return Factory.Menu()
Test().run()
API - kivymd.uix.menu
¶
-
class
kivymd.uix.menu.
MDMenuItem
¶ Bases:
kivy.uix.recycleview.views.RecycleDataViewBehavior
,kivy.uix.behaviors.ButtonBehavior
,kivy.uix.boxlayout.BoxLayout
-
text
¶
-
icon
¶
-
text_color
¶
-
-
class
kivymd.uix.menu.
MDMenu
¶ Bases:
kivy.uix.recycleview.RecycleView
-
width_mult
¶
-
-
class
kivymd.uix.menu.
MDDropdownMenu
(**kwargs)¶ Bases:
kivymd.theming.ThemableBehavior
,kivy.uix.boxlayout.BoxLayout
-
width_mult
¶ This number multiplied by the standard increment (56dp on mobile, 64dp on desktop, determines the width of the menu items.
If the resulting number were to be too big for the application Window, the multiplier will be adjusted for the biggest possible one.
-
max_height
¶ The menu will grow no bigger than this number.
Set to 0 for no limit. Defaults to 0.
-
border_margin
¶ Margin between Window border and menu
-
ver_growth
¶ Where the menu will grow vertically to when opening
Set to None to let the widget pick for you. Defaults to None.
-
hor_growth
¶ Where the menu will grow horizontally to when opening
Set to None to let the widget pick for you. Defaults to None.
-
background_color
¶ Color of the background of the menu
-
color_rectangle
¶ Color of the rectangle of the menu
-
width_rectangle
¶ Width of the rectangle of the menu
-
open
(self, *args)¶
-
display_menu
(self, caller)¶
-
on_touch_down
(self, touch)¶
-
on_touch_move
(self, touch)¶
-
on_touch_up
(self, touch)¶
-
on_dismiss
(self)¶
-
dismiss
(self)¶
-