Kivy – Text Markup


Kivy – Text Markup



”;


Although Kivy”s Label object has properties such as bold, italics and color, etc., it also provides markup facility to decorate the label text using a syntax similar to HTML tags. For the markup to show effect, you need to set the markup property of the label to True.


l = Label(text=''Hello [b]World[/b]'', markup=True)

Note that the kivy markup can be used only for inline styling. Instead of the tags with angular brackets as in HTML (as <b>Hello</b>), square brackets are used here (example: [b]Hello</b])

The text with this markup syntax is very much similar to the HTML syntax, as the following table shows −






HTML Kivy Markup
<b>bolded text</b> [b]bolded text[/b]
<i>italicized text</i> [i]italicized text[/i]
<u>underlined text</u> [u]underlined text[/u]

The following tags can be used for inline styling of the text property of label widget −














Sr.No Text Property & Description
1

[b][/b]

Activate bold text

2

[i][/i]

Activate italic text

3

[u][/u]

Underlined text

4

[s][/s]

Strikethrough text

5

[font=<str>][/font]

Change the font (str should be name of TTF file)

6

[font_family=<str>][/font_family]

Font family to request for drawing.

7

[size=<size>][/size]

Change the font size. <size> should be an integer.

8

[color=#<color>][/color]

Change the text color

9

[anchor=<str>]

Put an anchor in the text.

10

[sub][/sub]

Display the text at a subscript position relative to the text before it.

11

[sup][/sup]

Display the text at a superscript position relative to the text before it.

If you need to escape the markup from the current text, use kivy.utils.escape_markup().

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *