Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : How to make label bold in kivy

I am using Popup widgets in python-2.7 and kivy.Can someone help me?
1. How to make label bold ? (ex. text: "make label bold")
2. How to change color of title ? (ex. title : "change title color")

test.py

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

test.kv

<abc>
    title : "change title color"
    BoxLayout:
        orientation: "vertical"
        GridLayout:
            Label:
                text: "make label bold"
like image 871
macson taylor Avatar asked Sep 07 '18 12:09

macson taylor


1 Answers

Bold Label Text

There are two methods to making label's text bold. They are as follow:

Method 1

Use 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.

Method 2

Use Markup text, markup: True

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

Change Title Color

Use 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].

Example

main.py

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

Output

Img01

like image 52
ikolim Avatar answered Sep 26 '22 11:09

ikolim