Changing the background color of a Button in Kivy

前端 未结 2 1848
不知归路
不知归路 2020-12-03 10:22

I\'m new to Kivy and having trouble specifying the background color of a Button. Here\'s my simple example:

# custombutton.py

from kivy.app import App
from          


        
2条回答
  •  庸人自扰
    2020-12-03 10:58

    It's been a while since this was first posted so maybe with updates they came up with a better solution:

    Button:
        background_normal: ''
        background_color: 1, .3, .4, .85
    

    Since the Button has a default grey, adding background color will only tint the button. By setting background_normal to '' that resets the default to white. From the white canvas the background_color works as you would expect.

    Documentation

    1) https://kivy.org/docs/api-kivy.uix.button.html?highlight=button#module-kivy.uix.button

提交回复
热议问题