我正在使用Kivy和KivyMD创建布局,希望更改MD按钮上显示的文本的颜色,但是该颜色仍然停留在浅蓝色上。
我在下面的代码中提供了一个示例示例。
.py代码
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代码
#: 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)
运行此命令时,我希望按钮文本为红色,但如上所述,它仍为浅蓝色。任何帮助表示赞赏!
答案 0 :(得分:1)
当前, MDRectangleFlatIconButton 和 MDRoundFlatIconButton 小部件的文本颜色将始终默认为theme_cls.primary_color
,即使具有属性theme_text_color: 'Custom'
和{{1 }}。
临时解决方法如下:
text_color: [1,0,0,1]
与您的自定义
button.py ,即kivymd.button.MDRectangleFlatIconButton
button.MDRectangleFlatIconButton
或/usr/local/lib/python3.7/dist-packages/kivymd
(由~/KivyMD
创建)中获取 button.py 的副本,或者下载并提取KivyMD Zip文件({ {3}}),然后应用以下更改替换:
git clone https://github.com/HeaTTheatR/KivyMD.git
具有:
theme_text_color: 'Custom'
text_color: root.theme_cls.primary_color
theme_text_color: root.theme_text_color
text_color: root.text_color