我是 Kivy 的新手,在指定按钮的背景颜色时遇到困难。这是我的简单例子:
# custombutton.py
from kivy.app import App
from kivy.uix.widget import Widget
class MyWidget(Widget):
pass
class CustomButtonApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
CustomButtonApp().run()
以及随附的 kv 文件custombutton.kv
:
#:kivy 1.7.2
<MyWidget>:
canvas:
Color:
rgb: (0.93, 0.93, 0.93)
Rectangle:
pos: self.pos
size: self.size
Button:
center: self.parent.center
font_size: 14
height: 28
background_color: (1.0, 0.0, 0.0, 1.0)
text: "I'm a Button"
我确信我错过了一些明显的东西,但我已经搞砸了一个多小时了,却一无所获。该按钮似乎呈现出淡淡的深红色:
这不是在 Kivy 中指定 Button 背景颜色的方法吗?
Thanks!
自从第一次发布以来已经有一段时间了,所以也许通过更新他们想出了更好的解决方案:
Button:
background_normal: ''
background_color: 1, .3, .4, .85
由于按钮具有默认的灰色,因此添加背景颜色只会给按钮着色。通过将background_normal设置为'',将默认值重置为白色。在白色画布上,background_color 可以按照您的预期工作。
文档
1) https://kivy.org/docs/api-kivy.uix.button.html?highlight=button#module-kivy.uix.button https://kivy.org/docs/api-kivy.uix.button.html?highlight=button#module-kivy.uix.button
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)