Reputation: 155
When I try to open my dropdown menu nothing happens here is the python code:
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu
from kivy.properties import ObjectProperty
class app(MDApp):
dropdown = ObjectProperty
def print(self):
print("pressed!")
def on_start(self):
self.dropdown = MDDropdownMenu()
self.dropdown.items.append({"viewclass":"MDMenuItem","text":"Option 1"})
def build(self):
return Builder.load_file("main.kv")
app().run()
Here is the .kv file:
MDBoxLayout:
orientation: "vertical"
MDToolbar:
title: "MDToolbar"
left_action_items: [["menu", lambda x: app.dropdown.open()]]
MDLabel:
text: "Content"
halign: "center"
I hope that someone whos knows what they are doing can help me because I need it. Thank you in advance.
Upvotes: 1
Views: 717
Reputation: 38992
I believe you must provide a caller
for the MDDropdownMenu
, which is used to position the MDDropdownMenu
. If you add an id
for the MDToolBar
in your kv:
MDToolbar:
id: toolbar
title: "MDToolbar"
left_action_items: [["menu", lambda x: app.dropdown.open()]]
Then you can provide a caller
like this:
self.dropdown = MDDropdownMenu(caller=self.root.ids.toolbar.ids.left_actions)
Upvotes: 1