Kivy RecycleBoxLayout изменить цвет шрифта - PullRequest
0 голосов
/ 01 августа 2020

Мне не удалось найти способ изменить цвет шрифта для kivy recyclebox. Как изменить свойства метки? Ниже мой код.

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:

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'

Я попытался создать разметку для метки и изменить цвет напрямую. Ни один из методов у меня не помог. Есть ли способ его изменить?

1 Ответ

0 голосов
/ 01 августа 2020

Чтобы изменить цвет текста в виджете Label, нужно указать c атрибут, цвет .

фрагменты

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

Пример

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()

Вывод

RecycleView - текст ярлыка розовый

...