Label — Kivy v1.0.1-dev documentation

# Label

The label widget is a widget for rendering text. You can use ascii strings or unicode strings.

Snippet

    # hello world text
    l = Label(text='Hello world')

    # multiline text
    l = Label(text='Multi\nLine')

    # size
    l = Label(text='Hello world', font_size=20)

class `kivy.uix.label.` `Label`(**kwargs)

  Bases: `kivy.uix.widget.Widget`

  Label class, see module documentation for more information.

  `bold`

    Indicate if you want to use 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`, default to False

  `color`

    Text color, in the format (r, g, b, a)

    `color` is a `ListProperty`, default to [1, 1, 1, 1].

  `font_name`

    File of the font to use. The path used for the font can be a absolute path, or a relative path that will be search with the `resource_find()` function.

    Warning

    Depending of your text provider, the font file can be ignored. But you can mostly use this without trouble.

    `font_name` is a `StringProperty`, default to ‘fonts/DejaVuSans.ttf’.

  `font_size`

    Font size of the text. The font size is in pixels.

    `font_size` is a `NumericProperty`, default to 10.

  `halign`

    Horizontal alignment of the text.

    `halign` is a `OptionProperty`, default to ‘left’. Available options are : left, center and right.

  `italic`

    Indicate if you want to use the italic version of your font.

    Note

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

    `italic` is a `BooleanProperty`, default to False

  `padding`

    Padding of the text, in the format (padding_x, padding_y)

    `padding` is a `ReferenceListProperty` of (`padding_x`, `padding_y`) properties.

  `padding_x`

    Horizontal padding of the text, inside the widget box.

    `padding_x` is a `NumericProperty`, default to 0

  `padding_y`

    Vertical padding of the text, inside the widget box.

    `padding_x` is a `NumericProperty`, default to 0

  `text`

    Text of the label.

    Creation of a simple hello world

        widget = Label(text='Hello world')

    If you want to create the widget with an unicode string, use

        widget = Label(text=u'My unicode string')

    `text` a `StringProperty`.

  `texture`

    Texture object of the text. The text is rendered after each properties changes, and stored inside this property. You can use this `texture` for any graphics elements.

    Depending of the texture creation, the value will be a `Texture` or `TextureRegion` object.

    Warning

    The texture update is scheduled for the next frame. That’s mean if you really want the texture just after changing a property, you need to call `texture_update()` function before

        l = Label(text='Hello world')
        # l.texture is good
        l.font_size = 50
        # l.texture is not updated yet
        l.update_texture()
        # l.texture is good now.

    `texture` is a `ObjectProperty`, default to None.

  `texture_size`

    Texture size of the text.

    Warning

    The texture size is set after the texture property. So if you listen on the change to `texture`, the property texture_size will be not yet updated. Use self.texture.size instead.

  `texture_update`(*largs)

    Force texture recreation with the current Label properties.

    After this function call, the `texture` and :data`texture_size` will be updated in this order.

  `valign`

    Vertical alignment of the text.

    `valign` is a `OptionProperty`, default to ‘bottom’. Available options are : bottom, middle and top.