![](/img/trans.png)
[英]Kivy-If A button bind with callback(instance), how to call other functions
[英]How to callback many function in each button in FloatingActionButtonSpeedDial in kivy?
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' function 創建了 3 個回調 function 但它同時執行所有回調。 如果你通過'if'解決了它 function show 上傳到這里。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.