Skip to content

Label

Create a label that shows a line of text.

A label starts out just big enough for its text. If you give it another size (with setSize(), or with resize=False in setText() or setFont()), the text lines up inside it by the label's alignment, centered top to bottom, and any text that does not fit is cut off.

Creating a Label

You can create a Label using the following functions:

Label(text)
Label(text, alignment, textColor, backgroundColor, font, visibility)
Parameter Type Default Description
text str required The text to show.
alignment int LEFT How the text lines up, one of LEFT, CENTER, or RIGHT.
textColor Color Color.BLACK The text color.
backgroundColor Color Color.CLEAR The color behind the text. Defaults to transparent.
font Font None The font, for example Font("Serif", Font.ITALIC, 16). If omitted, the default font (Arial, size 13) is used.
visibility int 100 How visible the label is, from 0 (invisible) to 100 (fully visible).

For example,

label = Label("Hello World!")

Once created, you can add it to a Display using the Display's add() function.

Functions

Once a Label has been created, the following functions are available:

Function Description
getText() Return the label's text.
setText(text) Set the label's text.
getAlignment() Return how the label's text lines up.
setAlignment(alignment) Set how the label's text lines up.
getFont() Return the label's font.
setFont(font) Set the label's font.
getColor() Return the label's background color.
setColor(color) Set the label's background color.
getTextColor() Return the label's text color.
setTextColor(color) Set the label's text color.
getBackgroundColor() Return the label's background color. Same as getColor().
setBackgroundColor(color) Set the label's background color. Same as setColor().

Additionally, the following common functions are available: