kivy如何在按下MDFloatingActionButtonSpeedDial后添加功能

2024-10-03 23:21:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是kivymd中的浮动操作按钮快速拨号。我想在按下单个按钮后添加功能(导航到另一个屏幕)。谁能举个例子告诉我怎么做

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

<TestScreen>:
    name: "test"

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

我尝试了一些像普通按钮的东西,但它没有 不行

on_release:
         root.manager.current = "test"

Tags: nametest功能homedata屏幕按钮例子
1条回答
网友
1楼 · 发布于 2024-10-03 23:21:44

您可以将callback添加到MDFloatingActionButtonSpeedDial

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

使用应用程序中定义的call()方法:

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

然后,按下任何按钮都将触发call()方法

相关问题 更多 >