猕猴桃下拉菜单中的文本颜色

时间:2019-06-19 13:29:19

标签: python kivy

因此,我试图在下拉菜单中为某些文本着色,而我的部分代码当前如下所示:

DropDown:

        id: dropdown
        on_select: btn.text = '{}'.format(args[1])

        Button:
            text: '[color=333333]Some Text which is Black[/color]'
            size_hint_y: None
            height: '24dp'
            width:'130dp'
            on_release: dropdown.select('Some Text i dont know how to color')
            markup: True

如果我尝试在release命令中添加[color = 333333] ... [/ color],它不会为文本着色,而是显示标签。 谁知道我该如何解决?

1 个答案:

答案 0 :(得分:0)

在主按钮上添加markup: True

示例

main.py

from kivy.base import runTouchApp
from kivy.lang import Builder


runTouchApp(Builder.load_string("""
Screen:

    Button:
        id: btn
        text: 'Hello'
        size_hint: None, None
        markup: True
        height: '24dp'
        width: '200dp'
        on_release: dropdown.open(self)

    Widget:
        on_parent: dropdown.dismiss()

    DropDown:
        id: dropdown
        on_select: btn.text = '{}'.format(args[1])

        Button:
            text: 'My first Item'
            size_hint_y: None
            height: '24dp'
            on_release: dropdown.select(self.text)
        Label:
            text: '[color=ff3333]Unselectable item[/color]'
            markup: True
            size_hint_y: None
            height: '24dp'
        Button:
            text: 'My second Item'
            size_hint_y: None
            height: '24dp'
            on_release: dropdown.select(self.text)
        Button:
            markup: True
            text: '[color=ff3333]Hello[/color] [color=3333ff]World[/color]'
            size_hint_y: None
            height: '24dp'
            on_release: dropdown.select(self.text)
        Button:
            markup: True
            text: '[color=333333]Some Text which is Black[/color]'
            size_hint_y: None
            height: '24dp'
            on_release: dropdown.select(self.text)
"""))

输出

Dropdown opened Hello World selected