Change Icon color

363 views
Skip to first unread message

Charles longwe

unread,
Jan 31, 2023, 8:16:45 AM1/31/23
to Kivy users support
How can I change the color of Icon in  MDIconButton

Claver Barreto

unread,
Jan 31, 2023, 8:44:51 AM1/31/23
to Kivy users support
hello mate. you can change the color of a MDIconButton by adding the following parameter to it:

theme_icon_color: "Custom"
icon_color: 1,0,0,1 #you can add any color, i chose red just as an example

these parameters should be used in the .kv file, consider this code that as an example:

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDScreen:

    MDIconButton:
        icon: "language-python"
        pos_hint: {"center_x": .5, "center_y": .5}
        theme_icon_color: "Custom"
        icon_color: 1,0,0,1# substitute this color with whatever you want
'''


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


Example().run()

copy the code and it, change the color of the button and see if this is what you wanted.
the code was taken from the kivymd documentation, there is the information on how to change the color of the icon too, here's the link just in case: https://kivymd.readthedocs.io/en/latest/components/button/#mdiconbutton

Charles longwe

unread,
Feb 1, 2023, 7:39:34 AM2/1/23
to Kivy users support
Thanks alot
Reply all
Reply to author
Forward
0 new messages