更改 KIVY 中按钮的 On_press 颜色

时间:2021-02-01 13:18:44

标签: python kivy

enter image description here

上面是按钮按下时的按钮颜色。
在 .kv 文件中,我给出了 # Just for an example

Button:
                text:"Click here to print Hello world  "
                size_hint:[.9, .1]
                on_press: print("Hello world")

我应该怎么做才能改变按钮的 on_press 颜色?

要求更改在 .kv 文件中

1 个答案:

答案 0 :(得分:0)

您可以使用 background_downButton 属性设置按下 Button 时的背景颜色。不幸的是,background_down 必须是图像,而不是颜色元组。但是图像本身可以只是 1 x 1 像素的图像。例如,使用名为 red.png 的 1 x 1 像素图像作为 background_down

Button:
    text:"Click here to print Hello world  "
    size_hint:[.9, .1]
    on_press: print("Hello world")
    background_down: 'red.png'
相关问题