本文介紹了在kivy中更改按鈕或標簽文本顏色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在關注 這本 kivy 書,雖然我能理解如何更改按鈕的背景顏色,我沒有找到更改文本顏色的關鍵字.
I'm following this kivy book, and while I can understand how to change the background color of buttons, I haven't found the keyword to change the text color.
我看到了 這個和 其他問題.這是我的代碼:
I saw this and other questions. Here's my code:
#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.graphics import Color, Ellipse, Rectangle
class MinimalApp(App):
title = 'My App'
def build(self):
root = RootLayout()
return(root)
class RootLayout(GridLayout):
pass
if __name__ == '__main__':
MinimalApp().run()
在 .kv 文件中:
#:kivy 1.7.2
#:import kivy kivy
<RootLayout>:
rows: 1
Label:
text: "Why does this not work?"
# rgba: 1,0,1,1 # doesn't work
# Color: # doesn't work
# rgba: 1,0,1,1 # doesn't work
# font_color: rgba: 1,0,1,1
canvas.before:
Color:
rgba: 0, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
推薦答案
使用color
(全部小寫):
Use color
(all lowercase):
<RootLayout>:
rows: 1
Label:
text: "Why does this not work?"
color: 1,0,1,1 # <-----------
canvas.before:
Color:
rgba: 0, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
這篇關于在kivy中更改按鈕或標簽文本顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!