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 kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
<MagicButton@MagicBehavior+MDRectangleFlatButton>


MDFloatLayout:

    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()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/magic-button.gif

API - kivymd.uix.behaviors.magic_behavior

class kivymd.uix.behaviors.magic_behavior.MagicBehavior
magic_speed

Animation playback speed.

magic_speed is a NumericProperty and defaults to 1.

grow(self)

Grow effect animation.

shake(self)

Shake effect animation.

wobble(self)

Wobble effect animation.

twist(self)

Twist effect animation.

shrink(self)

Shrink effect animation.

on_touch_up(self, *args)