gpt4 book ai didi

python : How to make label bold in kivy

转载 作者:行者123 更新时间:2023-12-04 11:43:03 28 4
gpt4 key购买 nike

我正在使用 Popup python-2.7 中的小部件和 kivy 。有人能帮我吗?
1.如何使标签加粗? (例如 text: "make label bold")
2. 如何改变标题的颜色? (例如 title : "change title color")

测试文件

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.popup import Popup

class abc(Popup):
def __init__(self, **kwargs):
super(abc, self).__init__(**kwargs)
self.open()


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


TestApp().run()

测试.kv
<abc>
title : "change title color"
BoxLayout:
orientation: "vertical"
GridLayout:
Label:
text: "make label bold"

最佳答案

粗体标签文本

有两种方法可以使标签的文本加粗。它们如下:

方法一

使用 bold: True

Label:
bold: True

Label » bold

bold

Indicates use of the bold version of your font.

Note

Depending of your font, the bold attribute may have no impact on your text rendering.

bold is a BooleanProperty and defaults to False.



方法二

使用 Markup text , markup: True
Label:
markup: True
text: '[b]make label bold[/b]

更改标题颜色

使用 title_color
<abc>
title : "change title color"
title_color: [1, 0, 0, 1] # red title

Popup » title_color

title_color

Color used by the Title.

title_color is a ListProperty and defaults to [1, 1, 1, 1].



例子

主文件
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.lang import Builder


Builder.load_string('''
#:kivy 1.11.0

<abc>
title : "change title color"
title_color: 1, 0, 0, 1 # red title
BoxLayout:
orientation: "vertical"
GridLayout:
cols: 1
Label:
bold: True
text: "make label bold"

Label:
markup: True
text: "[b]make label bold[/b]"

''')


class abc(Popup):
pass


class PopupApp(App):
title = 'Popup Demo'

def build(self):
self._popup = abc()
return Button(text="press me", on_press=self._popup.open)


PopupApp().run()

输出

Img01

关于 python : How to make label bold in kivy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52222205/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com