简体   繁体   English

Kivy RecycleBoxLayout 更改字体颜色

[英]Kivy RecycleBoxLayout change font color

I have been unable to find a way to change the font color for kivy recyclebox.我一直无法找到更改 kivy 回收箱字体颜色的方法。 How do I change the label properties?如何更改 label 属性? Below is my code.下面是我的代码。

Python side: Python侧:

class ExampleViewer(RecycleView): 
    def __init__(self, **kwargs): 
        super(ExampleViewer, self).__init__(**kwargs) 
        self.data = [{'text': f"[color=[0,0,0,1]]{x}[/color]"} for x in range(20)]

Kivy Side: Kivy 侧:

ExampleViewer: 
    viewclass: 'Label'  # defines the viewtype for the data items. 
    orientation: "vertical"
  
    RecycleBoxLayout: 
        color: (0, 0, 0, 1)
        default_size: None, dp(56)
        markup: True 
  
        # defines the size of the widget in reference to width and height 
        default_size_hint: 1, None 
        size_hint_y: None
        height: self.minimum_height 
        orientation: 'vertical'

I've tried creating a markup for the label and changing the color directly.我尝试为 label 创建标记并直接更改颜色。 Neither method has worked for me.这两种方法都不适合我。 Is there a way to change it?有没有办法改变它?

The way to change the colour of a text in Label widget is to specific the attibute, color .在 Label 小部件中更改文本颜色的方法是指定属性color

Snippets片段

self.data = [{'text': str(x), 'color': [1, 0, 1, 1]} for x in range(20)]

Example例子

main.py主文件

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView

Builder.load_string('''
<RV>:
    viewclass: 'Label'
    RecycleBoxLayout:
        default_size: None, dp(56)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
''')


class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.data = [{'text': str(x), 'color': [1, 0, 1, 1]} for x in range(100)]


class TestApp(App):
    def build(self):
        return RV()


if __name__ == '__main__':
    TestApp().run()

Output Output

RecycleView - 标签的文本是粉红色的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM