也就是他按下按鈕,1號功能啟動,再次按下,2號功能啟動。2號功能一次又一次按下,以此類推……單個MDFloatingActionButton怎么辦?
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.button.button import MDFloatingActionButton
KV = '''
MDFloatLayout:
MDFloatingActionButton:
icon: "flashlight"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.foo1() and app.foo2()
'''
class Test(MDApp):
def build(self):
screen = Builder.load_string(KV)
return screen
def foo1(self):
print("foo1")
def foo2(self):
print("foo2")
Test().run()
uj5u.com熱心網友回復:
MDFloatingActionButton:
icon: "flashlight"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release:
app.foo1()
app.foo2()
應該這樣做
編輯:對不起,我好像誤解了你的問題。這是你應該怎么做
from kivymd.app import MDApp
from kivy.lang import Builder
KV = '''
MDFloatLayout:
MDFloatingActionButton:
icon: "flashlight"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.button_on_release()
'''
class Test(MDApp):
release_count = 0
def build(self):
screen = Builder.load_string(KV)
return screen
def button_on_release(self):
if self.release_count == 0:
self.foo1()
self.release_count = 1
return
if self.release_count == 1:
self.foo2()
self.release_count = 0
return
def foo1(self):
print("foo1")
def foo2(self):
print("foo2")
Test().run()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425238.html
標籤:按钮
上一篇:HTML中按鈕的惱人藍色
下一篇:我的按鈕卡在Y/垂直軸上
