macson taylor
macson taylor

Reputation: 181

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"

Upvotes: 8

Views: 11215

Answers (2)

ikolim
ikolim

Reputation: 16031

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

Upvotes: 12

Vishal R
Vishal R

Reputation: 66

You may refer to the API here

  1. It is a boolean with default as False, So you may use as: Label: text: 'blah blah' bold: True
  2. You may try adding color with the following tag:

    color: [0.941, 0, 0,1]

That should show in red color. It uses the format as RGBA (A for Alpha/Opacity). You can use this tool to choose your color.

Upvotes: 1

Related Questions