ToggleButton#

#

This behavior must always be inherited after the button’s Widget class since it works with the inherited properties of the button class.

example:

class MyToggleButtonWidget(MDButton, MDToggleButton):
    # [...]
    pass
from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDButton

KV = '''
MDScreen:

    MDBoxLayout:
        adaptive_size: True
        spacing: "12dp"
        pos_hint: {"center_x": .5, "center_y": .5}

        MyToggleButton:
            group: "x"

            MDButtonText:
                text: "Show ads"

        MyToggleButton:
            group: "x"

            MDButtonText:
                text: "Do not show ads"

        MyToggleButton:
            group: "x"

            MDButtonIcon:
                icon: "pencil"

            MDButtonText:
                text: "Does not matter"
'''


class MyToggleButton(MDButton, MDToggleButton):
    ...


class Test(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/toggle-button-1.gif

You can inherit the MyToggleButton class only from the following classes#

  • MDRaisedButton

  • MDFlatButton

  • MDRectangleFlatButton

  • MDRectangleFlatIconButton

  • MDRoundFlatButton

  • MDRoundFlatIconButton

  • MDFillRoundFlatButton

  • MDFillRoundFlatIconButton

API - kivymd.uix.behaviors.toggle_behavior#

class kivymd.uix.behaviors.toggle_behavior.MDToggleButtonBehavior(*args, **kwargs)#

This mixin class provides togglebutton behavior. Please see the togglebutton behaviors module documentation for more information.

Added in version 1.8.0.

background_normal#

Color of the button in rgba format for the ‘normal’ state.

background_normal is a ColorProperty and is defaults to None.

background_down#

Color of the button in rgba format for the ‘down’ state.

background_down is a ColorProperty and is defaults to None.

font_color_normal#

Color of the font’s button in rgba format for the ‘normal’ state.

font_color_normal is a ColorProperty and is defaults to None.

font_color_down#

Color of the font’s button in rgba format for the ‘down’ state.

font_color_down is a ColorProperty and is defaults to None.

set_properties(*args)#