0
from kivymd.app import MDApp
from kivy.lang import Builder
Screen='''
Screen: 


MDFloatingActionButtonSpeedDial:
    callback:app.callback
    data:app.data
    rotation_root_button:True
    hint_animation:True
    bg_hint_color: app.theme_cls.primary_light
'''
class Wolf(MDApp):
    data = {
        'help-rhombus': 'Help',
        'triangle': 'Setting',
        'key': 'Register', } #For running app
    def callback(self, instance):
        {What to do now,so that it can run different function with different button? }
        def build(self):
            self.theme_cls.theme_style = 'Dark'
            self.theme_cls.primary_palette = 'Green'
            screen_r = Builder.load_string(screen)
            return screen_r

Wolf().run()

我使用“if”函数创建了 3 个回调函数,但它同时执行所有回调。如果你通过'if'函数解决了它,请在此处上传。

4

1 回答 1

0
from kivy.lang import Builder

from kivymd.app import MDApp

screen = '''
Screen: 

    MDFloatingActionButtonSpeedDial:
        callback:app.callback
        data:app.data
        rotation_root_button:True
        hint_animation:True
        bg_hint_color: app.theme_cls.primary_light
'''


class Wolf(MDApp):
    data = {
        'help-rhombus': 'Help',
        'triangle': 'Setting',
        'key': 'Register', }

    def callback(self, instance):
        if instance.icon == 'help-rhombus':
            print('Callback self.help-rhombus()')
        elif instance.icon == 'key':
            print('Callback self.key()')
        elif instance.icon == 'triangle':
            print('Callback self.triangles()')

    def build(self):
        self.theme_cls.theme_style = 'Dark'
        self.theme_cls.primary_palette = 'Green'
        screen_r = Builder.load_string(screen)
        return screen_r

Wolf().run()
于 2020-08-09T08:14:43.100 回答