KivyMD callback(self,instance) example
Question:
I am using a floating action button speed dial in kivymd. I have added the data dictionary and want to add separate functions to all the sub buttons. For that I have to use callback
. Can anyone tell me by an example how do I do it?
Kv code:
MDFloatingActionButtonSpeedDial:
callback: app.callback
data:app.data
Python code:
class Example(MDApp):
data = {
'language-python': 'Python',
'language-php': 'PHP',
'language-cpp': 'C++',
}
def build(self):
return Builder.load_string(KV)
Update
I followed up and found that callback:app.callback will be required to call the function.
Answers:
According to the documentation, you can just add a callback
method to your App
, like this:
class Example(MDApp):
data = {
'language-python': 'Python',
'language-php': 'PHP',
'language-cpp': 'C++',
}
def build(self):
return Builder.load_string(KV)
def callback(self, instance):
print(instance.icon)
I am using a floating action button speed dial in kivymd. I have added the data dictionary and want to add separate functions to all the sub buttons. For that I have to use callback
. Can anyone tell me by an example how do I do it?
Kv code:
MDFloatingActionButtonSpeedDial:
callback: app.callback
data:app.data
Python code:
class Example(MDApp):
data = {
'language-python': 'Python',
'language-php': 'PHP',
'language-cpp': 'C++',
}
def build(self):
return Builder.load_string(KV)
Update
I followed up and found that callback:app.callback will be required to call the function.
According to the documentation, you can just add a callback
method to your App
, like this:
class Example(MDApp):
data = {
'language-python': 'Python',
'language-php': 'PHP',
'language-cpp': 'C++',
}
def build(self):
return Builder.load_string(KV)
def callback(self, instance):
print(instance.icon)