【问题标题】:Text color in kivy Dropdown menukivy下拉菜单中的文本颜色
【发布时间】:2019-06-19 22:41:00
【问题描述】:

所以我正在尝试为下拉菜单中的一些文本着色,而我的部分代码目前如下所示:

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

如果我尝试在发布命令中添加 [color=333333]...[/color],它不会为文本着色,而是显示标签。 有人知道我该如何解决这个问题吗?

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    将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)
    """))
    

    输出

    【讨论】:

      猜你喜欢
      • 2014-03-31
      • 2023-02-01
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2019-09-24
      • 1970-01-01
      相关资源
      最近更新 更多