Class GLabel

GLabel(**keywords)

Instances represent an (uneditable) text label

The attribute text defines the content of this image. Uses of the escape character ‘n’ will result in a label that spans multiple lines. The label includes both the text, and a rectangular backdrop with bottom left corner at pos and width and height size. The background color of this rectangle is fillcolor, while linecolor is the color of the text.

The text itself is aligned within this rectangle according to the attributes halign and valign. See the documentation of these attributes for how alignment works. There are also attributes to change the point size, font style, and font name of the text. The size attribute of this label will grow to ensure that the text will fit in the rectangle, no matter the font or point size.

To change the font, you need a .ttf (TrueType Font) file in the Fonts folder; refer to the font by filename, including the .ttf. If you give no name, it will use the default Kivy font. The bold attribute only works for the default Kivy font; for other fonts you will need the .ttf file for the bold version of that font. See ComicSans.ttf and ComicSansBold.ttf for an example.

Constructor: creates a new text label.

param keywords:dictionary of keyword arguments

Precondition: See below.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. For example, to create a label containing the word ‘Hello’, use the constructor call

GLabel(text=’Hello’)

This class supports the same keywords as GObject, as well as additional attributes for the text properties (e.g. font size and name).

This class is a subclass of GObject, and inherits all of its attributes and methods.

Attributes

These attributes are in addition to those from GObject.

text

Text for this label.

The text in the label is displayed as a single line, or broken up into multiple lines in the presence of the escape character ‘n’. The size attribute of this label grows to make sure that the entire text fits inside of the rectangle.

Invariant: string

font_size

Size of the text font in points.

Invariant: A positive number (int or float)

font_name

File name for the .ttf file to use as a font

Invariant: string referring to a .ttf file in folder Fonts

bold

Boolean indicating whether or not the text should be bold.

Only works on the default Kivy font. Does not work on custom .ttf files. In that case, you need the bold version of the .ttf file. See ComicSans.ttf and ComicSansBold.ttf for an example.

Invariant: boolean

halign

Horizontal alignment for this label.

The text is anchored inside of the label rectangle on either the left, the right or the center. This means that as the size of the label increases, the text will still stay rooted at that anchor.

Invariant: one of ‘left’, ‘right’, or ‘center’

valign

Vertical alignment for this label.

The text is anchored inside of the label rectangle at either the top, the bottom or the middle. This means that as the size of the label increases, the text will still stay rooted at that anchor.

Invariant: one of ‘top’, ‘bottom’, or ‘middle’

linecolor

The object line color.

Used to color the foreground, text, or, in the case of solid shapes, the shape border.

Invariant: Must be a 4-element list of float between 0 and 1. If you assign it a RGB or HSV object from module colormodel, it will convert the color for your automatically.

Table Of Contents

Previous topic

Class GImage

Next topic

Color Models

This Page