I am trying to fetch the selection of a MDDropwdownMenu
inside my kv file I am using a MDRaisedButton
by the following code
MDRaisedButton:
id: select_warning_image_Button
text: "Menu labels"
opposite_colors: True
elevation_normal: 0
on_release: MDDropdownMenu(items=app.menu_labels, width_mult=4).open(self)
In my main.py
(see below) I have a class called MainApp
which inherits from App
. Inside this class I have created the attribute variable menu_labels
. I want to use the function change_variable
to set the value of the variable VARIABLE
to the value of the menu. But I cannot seem to be able to use self.change_variable(…). Is there a value to fire a function when a specific value in the dropdown is selected?
# main.py
import …
class MainApp(App):
VARIABLE = ""
menu_labels = [
{"viewclass": "MDMenuItem",
"text": "Label1",
"on_release": self.change_variable("Label1")},
{"viewclass": "MDMenuItem",
"text": "Label2",
"on_release": self.change_variable("Label2")},
]
def change_variable(self, label):
self.VARIABLE = label