Changing the background color of a Button in Kivy

前端 未结 2 1853
不知归路
不知归路 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条回答
  •  旧时难觅i
    2020-12-03 10:51

    Ah, this is a common confusion. The problem is that Button.background_color really works as a kind of tint, not just a block colour. Since the default background is a grey image (the one you normally see if you make an unstyled button), what you end up seeing is a red tint to that grey image - which comes out as the dark red you observe.

    You can get the behaviour you want by replacing the background image to just one that's plain white (it doesn't have to be more than a few pixels), or by otherwise playing with the background_normal and background_down properties. When your background_color tints the new pure white image, you get the pure red you're after.

    I guess this isn't so clear in the docs, I'll try to improve it.

提交回复
热议问题