Skip to content

Label

Create a label that shows a line of text.

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 system default font 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 label has been created, the following functions are available:

Function Description
label.getText() Return the label's text.
label.getAlignment() Return how the label's text lines up.
label.getFont() Return the label's font.
label.setText(text) Set the label's text.
label.setAlignment(alignment) Set how the label's text lines up.
label.setFont(font) Set the label's font.

Position

Function Description
label.getPosition() Return the object's position, the top-left corner of its bounding box.
label.getX() Return the object's horizontal position.
label.getY() Return the object's vertical position.
label.getCenter() Return the object's center point.
label.getCenterX() Return the object's horizontal center.
label.getCenterY() Return the object's vertical center.
label.setPosition(x, y) Move the object so the top-left corner of its bounding box sits at the given point.
label.setX(x) Set the object's horizontal position.
label.setY(y) Set the object's vertical position.
label.setCenter(x, y) Move the object so its center sits at the given point.
label.setCenterX(x) Set the object's horizontal center.
label.setCenterY(y) Set the object's vertical center.
label.move(x, y) Move the object to a new position.

Size

Function Description
label.getSize() Return the object's width and height.
label.getWidth() Return the object's width.
label.getHeight() Return the object's height.
label.setSize(width, height) Set the object's width and height.
label.setWidth(width) Set the object's width.
label.setHeight(height) Set the object's height.

Rotation

Function Description
label.getRotation() Return how far the object is turned.
label.setRotation(rotation) Turn the object to a given angle.
label.rotate(angle) Turn the object by an additional angle.

Visibility

Function Description
label.getVisibility() Return how visible the object is.
label.setVisibility(visibility) Set how visible the object is.

Color

Function Description
label.getColor() Return the shape's text color.
label.getTextColor() Return the label's text color.
label.getBackgroundColor() Return the label's background color.
label.getFill() Report whether the shape is filled in.
label.getThickness() Return the shape's outline thickness.
label.setColor() Set the shape's text color.
label.setTextColor() Set the label's text color.
label.setBackgroundColor() Set the label's background color.
label.setFill(fill) Set whether the shape is filled in.
label.setThickness(thickness) Set the shape's outline thickness.

Information

Function Description
label.getEndpoints() Return the object's four corners.
label.getBoundingBox() Return the smallest upright box that surrounds the object.
label.getGroup() Return the Group this object belongs to.
label.getDisplay() Return the Display this object is on.
label.setToolTipText() Set the hover text shown over the object.

Hit Testing

Function Description
label.contains(x, y) Report whether a point lies inside the object.
label.intersects(other) Report whether this object overlaps another.
label.encloses(other) Report whether this object completely contains another.

Events

Function Description
label.onMouseClick(action) Set up a function to call when the mouse is clicked on this object.
label.onMouseDown(action) Set up a function to call when the mouse label is pressed on this object.
label.onMouseUp(action) Set up a function to call when the mouse label is released over this object.
label.onMouseMove(action) Set up a function to call when the mouse moves over this object.
label.onMouseDrag(action) Set up a function to call when the mouse is dragged over this object.
label.onMouseEnter(action) Set up a function to call when the mouse moves onto this object.
label.onMouseExit(action) Set up a function to call when the mouse moves off this object.
label.onKeyType(action) Set up a function to call when a key is typed (pressed and released).
label.onKeyDown(action) Set up a function to call when a key is pressed down.
label.onKeyUp(action) Set up a function to call when a key is released.