Context Menu¶
Example¶
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.theming import ThemeManager
kv = '''
FloatLayout:
MDContextMenu:
menu: app.menu
pos_hint: {'top': 1}
on_enter: app.on_enter(*args)
MDContextMenuItem:
text: 'File'
MDContextMenuItem:
text: 'Edit'
'''
MENU = [
[
"File",
[
{"Item 1": []},
{
"Item 2": [
"Item 1",
"Item 2",
"Separator",
["language-python", "Item 3"],
]
},
"Separator",
{"Item 3": []},
{
"Item 4": [
["language-python", "Item 1"],
["language-cpp", "Item 2"],
"Separator",
["language-swift", "Item 3"],
]
},
"Separator",
{"Item 5": []},
],
],
[
"Edit",
[
{"Item 1": []},
["language-swift", "Item 3"]
]
]
]
class Test(MDApp):
context_menu = None
menu = MENU
def on_enter(self, instance):
'''
:type instance: <kivymd.context_menu.MDContextMenu object>
'''
print(instance.current_selected_menu.text)
def build(self):
root = Builder.load_string(kv)
return root
Test().run()
API - kivymd.uix.context_menu
¶
-
class
kivymd.uix.context_menu.
MDContextDropdownMenu
¶ Bases:
kivymd.uix.menu.MDDropdownMenu
-
menu_item
¶
-
display_menu
(self, caller)¶
-
-
class
kivymd.uix.context_menu.
BasedMenuItem
¶ Bases:
kivy.uix.boxlayout.BoxLayout
,kivymd.uix.behaviors.HoverBehavior
,kivymd.theming.ThemableBehavior
List item for toolbar context menu.
-
text
¶ Text of Item.
-
background_color
¶ Background color of Item.
-
selected_color
¶ Selected color of Item.
-
arrow_right
¶ The path to the image of the right arrow.
-
color_text_item_menu_header
¶ Header color for context menu items.
-
context_menu
¶ <kivymd.context_menu.MDContextMenu object>.
-
name_item_menu
¶ The currently selected context menu header item.
-
on_enter
(self)¶
-
on_leave
(self)¶
-
-
class
kivymd.uix.context_menu.
MenuItem
¶
-
class
kivymd.uix.context_menu.
MenuIconItem
¶ Bases:
kivymd.uix.context_menu.BasedMenuItem
,kivymd.theming.ThemableBehavior
-
icon
¶
-
icon_color
¶
-
icon_size
¶
-
-
class
kivymd.uix.context_menu.
MDContextMenuItem
(**kwargs)¶ Bases:
kivy.uix.boxlayout.BoxLayout
,kivymd.theming.ThemableBehavior
,kivymd.uix.behaviors.HoverBehavior
An item inside the context menu header.
-
text
¶ Text item
-
color_active
¶ Color of the item when it is selected.
-
text_color
¶ Color of the item.
-
on_enter
(self)¶ Called when the mouse cursor hovers over one of the items in the header of the context menu.
-
diactivate_item
(self)¶
-
-
class
kivymd.uix.context_menu.
MDContextMenu
(**kwargs)¶ Bases:
kivy.uix.boxlayout.BoxLayout
,kivymd.theming.ThemableBehavior
MDContextMenu.
- Events
- on_enter
Called when an item is selected in the context menu header
- on_leave
Called when the context menu is closed
-
menu
¶
-
background_color_context_menu
¶ Context menu background color.
-
selected_color_item_context_menu
¶ The highlight color of the current item in the context menu.
-
background_color_menu_header
¶ Header color for context menu items.
-
color_text_item_menu_header
¶ Header color for context menu items.
-
icon_color
¶ The color of the icons used for menu items.
-
icon_size
¶ The size of the icons used for menu items.
-
separator_height
¶ Line separator height.
-
context_menu_open
= False¶ Open or close context menu.
-
context_submenu_open
= False¶ Open or close context sub menu.
-
current_selected_menu
¶ Object of the selected item in the context menu header.
-
current_selected_item
=¶ Name of the selected item in the context menu.
-
sub_menu
¶ Submenu object.
-
on_enter
(self)¶ Called when an item is selected in the context menu header.
-
on_leave
(self)¶ Called when the context menu is closed.
-
add_separator
(self, list_menu)¶
-
add_icon_item
(self, list_menu, data)¶
-
generates_context_submenu
(self, instance_menu_item, name_item_menu, text)¶ Generates a sub menu.
-
generates_context_menu
(self, instance, name_item_menu)¶ Generates a menu.
-
open
(self, instance, name_item_menu)¶
-
open_menu
(self, instance, menu_list)¶
-
context_previous_menu_dismiss
(self, *args)¶ Called when closing the context menu.