Magic¶
Magical effects for buttons.
Warning
Magic effects do not work correctly with KivyMD buttons!
To apply magic effects, you must create a new class that is inherited from the
widget to which you apply the effect and from the MagicBehavior
class.
In KV file:
<MagicButton@MagicBehavior+MDRectangleFlatButton>
In python file:
class MagicButton(MagicBehavior, MDRectangleFlatButton):
pass
The MagicBehavior
class provides five effects:
Example:
from kivymd.app import MDApp
from kivy.lang import Builder
KV = '''
#:import MagicBehavior kivymd.uix.behaviors.MagicBehavior
<MagicButton@MagicBehavior+MDRectangleFlatButton>
FloatLayout:
MagicButton:
text: "WOBBLE EFFECT"
on_release: self.wobble()
pos_hint: {"center_x": .5, "center_y": .3}
MagicButton:
text: "GROW EFFECT"
on_release: self.grow()
pos_hint: {"center_x": .5, "center_y": .4}
MagicButton:
text: "SHAKE EFFECT"
on_release: self.shake()
pos_hint: {"center_x": .5, "center_y": .5}
MagicButton:
text: "TWIST EFFECT"
on_release: self.twist()
pos_hint: {"center_x": .5, "center_y": .6}
MagicButton:
text: "SHRINK EFFECT"
on_release: self.shrink()
pos_hint: {"center_x": .5, "center_y": .7}
'''
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()