There are a few different ways to place your text with display_text labels. All of these settings are available for both Label and BitmapLabel.

x, y coordinates

 

The label can be placed using x, y coordinates. The default origin is located on the far left horizontally, and half the height vertically as shown in the image above.

Baseline Alignment

The base_alignment parameter can be set to True to change the vertical origin to point to the baseline of the text. This is helpful for lining up fonts of different sizes nicely next to each other. The default value is False.

Descenders

Many fonts have glyphs with descenders that drop down below the baseline. This image illustrates some of them:

Not all fonts use all of the same descenders on their glyphs. So your font may look different, but the concept should work the same for any that it does have. This example shows 'y' glyphs descending below the baseline and the effect of the base_alignment parameter on them.

Anchored Positioning

If you'd like more precise control over the placement of your text, you can use anchor_point and anchored_position instead of x and y coordinates. With this method, you can set the origin point anywhere you want within your Label. It's particularly useful for centering text within the display, or aligning it to the right edge of the display.

anchor_point is a tuple containing two float values. This is the point that your Label will get positioned relative to. 0.0 being left and top, and 1.0 being right and bottom with values between representing their location within the rectangle that makes up your label. The default is (0.0, 0.0) which is the top left corner.

Anchored Position

When you set the anchored_position, the label will move so that its anchor_point is aligned on top of the coordinates that you set for the anchored_position. The value is a tuple containing two integers that represent pixel coordinates on the display. There is a similar example in the library repository.

This guide was first published on Mar 09, 2021. It was last updated on 2021-03-09 10:58:42 -0500.

This page (Label Placement) was last updated on Oct 12, 2021.

Text editor powered by tinymce.