python - Why is my KivyMD Button not changing Color with "md_bg_color"? - Stack Overflow

时间: 2025-01-06 admin 业界

I am adding an MDButton to my kv file, as per the below code, and attempting to set a custom background color. It is not working, I have tried many different variations. I am using KivyMD 2.0.1

Initial attempt (i have simplified the code to include the button only):

MDScreen:
    MDButton:
        style: "tonal"
        md_bg_color: [232/255, 114/255, 83/255, 1]

        MDButtonText:
            text: "Next"

I have also tried:

MDButton:
    style: "filled"
    md_bg_color: [232/255, 114/255, 83/255, 1]
    pos_hint: {"center_x": 0.5, "center_y": 0.5}  # Adjust position
    size_hint: 0.3, 0.1  # Adjust size (optional)
    canvas.before:
        Color:
            rgba: [232/255, 114/255, 83/255, 1]  # Custom button color
        RoundedRectangle:
            pos: self.pos
            size: self.size
            radius: [10]  # Rounded corners (optional)
    MDButtonText:
        text: "Next"

I have read the docs and tried looking for similar issues, but most of the questions about this relate the previous version of Kivy and there are quite a few differences in KivyMD 2.0.1

最新文章