Reputation: 45
I'm creating a layout using Kivy and KivyMD and wish to change the colour of the text displayed in the MD buttons, however the colour remains stuck on a light blue.
I've included an example of what I tried in the code below.
.py code
import kivy, kivymd
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.theming import ThemeManager
class ButtonColorApp(App):
theme_cls = ThemeManager()
title='RUCES'
def build(self):
self.theme_cls.theme_style = "Dark"
sm = ScreenManager()
sm.add_widget(IntroPage(name="intro_page"))
return sm
class IntroPage(Screen):
#funcs and vars
pass
def main():
but = ButtonColorApp()
but.run()
if __name__ == "__main__":
main()
.kv code
#: import MDRectangleFlatIconButton kivymd.button.MDRectangleFlatIconButton
#: import MDLabel kivymd.label.MDLabel
<MyButton@MDRectangleFlatIconButton>:
text_size: self.size * 3
theme_text_color: 'Custom'
font_size: 20
md_bg_color: (0,0,.4,1)
canvas.before:
Color:
rgba: (0,0,0,1)
Line:
width: 0.5
rectangle: (self.x, self.y, self.width, self.height)
<IntroPage>:
BoxLayout:
orientation: "vertical"
MyButton:
size_hint_x: 1
theme_text_color: 'Custom'
text: "Colour Me!"
text_color: (1,0,0,1)
When I run this I expect the button text to be red but as mentioned above it remains light blue. Any help appreciated!
Upvotes: 3
Views: 6761
Reputation: 1
Another workaround is to use markup language, e.g.:
.kv
file assign "id"
to your MDButton
MDFlatButton:
id: info_btn
.py
fileself.ids.info_btn.text = '[color=#00ffcc]Info[/color]'
self.ids.info_btn.markup = True
Upvotes: 0
Reputation: 16031
Currently, the text colour for MDRectangleFlatIconButton and MDRoundFlatIconButton widgets will always default to the theme_cls.primary_color
even with attributes, theme_text_color: 'Custom'
and text_color: [1,0,0,1]
.
The temporary solution is as follow:
kivymd.button.MDRectangleFlatIconButton
with your customised
button.py i.e. button.MDRectangleFlatIconButton
/usr/local/lib/python3.7/dist-packages/kivymd
, or ~/KivyMD
(created by git clone https://github.com/HeaTTheatR/KivyMD.git
), or download and extract KivyMD Zip file (Download ZIP) , and apply the following changesReplace:
theme_text_color: 'Custom'
text_color: root.theme_cls.primary_color
with:
theme_text_color: root.theme_text_color
text_color: root.text_color
<MDRectangleFlatIconButton>
...
theme_text_color: 'Custom'
text_color: root.theme_cls.primary_color
BoxLayout:
...
MDIcon:
...
MDLabel:
..
theme_text_color: root.theme_text_color
text_color: root.text_color
markup: root.markup
<MDRoundFlatIconButton>
...
theme_text_color: 'Custom'
text_color: root.theme_cls.primary_color
BoxLayout:
...
MDIcon:
...
MDLabel:
...
theme_text_color: root.theme_text_color
text_color: root.text_color
markup: root.markup
Upvotes: 2