Search code examples
pythonkivykivy-languagekivymd

kivy- how to add function after press MDFloatingActionButtonSpeedDial


I am using a floating action button speed dial in kivymd. I want to add functions (navigate to the another screen) after press singular buttons. Can anyone tell me please by an example how do I do it?

<HomeScreen>:
    name: "home"
  MDFloatingActionButtonSpeedDial:
        data: 
            {'home': 'Domov',
            'lightning-bolt': 'Ciele',
            'notebook': 'Moje testy'}

<TestScreen>:
    name: "test"

<GoalsScreen>:
    name: "goals"
    
<HistoryScreen>:
    name: "history"

I tried something like normall buttons, but it doesn´ t work.

on_release:
         root.manager.current = "test"

Solution

  • You can add a callback to the MDFloatingActionButtonSpeedDial:

      MDFloatingActionButtonSpeedDial:
            callback: app.call
            data: 
                {'home': 'Domov',
                'lightning-bolt': 'Ciele',
                'notebook': 'Moje testy'}
    

    with the call() method defined in the app:

    def call(self, button):
        print('called from', button)
    

    Then any button press will trigger the call() method.