#Hello I m a coding novice and am trying

1 messages · Page 1 of 1 (latest)

winged sage
#

Now this is where I'm stuck. Looking at some Adafruit tutorials I think the next step is to create a label. But I'm not sure what a label is, and what function it serves?

#

matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(2, (matrixportal.graphics.display.height // 2) - 1),
)

#

I get that this defines what font to use, the x,y coords of the text but since I have 3 lines of text, is this just defining the top left corner of the text box?

#

Or should I be making a tuple for x,y coordinates to define where each row of text should be?

neat sedge
#

Label is a class that holds some text and shows it on a display that has been configured with displayio (the modern display framework in CircuitPython). There is a learn guide here that details them and their usage: https://learn.adafruit.com/circuitpython-display_text-library

However generally speaking with Matrix Portal and similar devices there are 2 main high level ways to code your project. Using the helper library like MatrixPortal library, OR going lower level and doing more manual setup of the things you want to use.

If you've already started down the path of using the MatrixPortal library, and you just want to add a few more lines of text but haven't run into any other issues or limitations I would recomend just sticking to using that library rather than starting to try to manually create your own labels.

Adafruit Learning System

Get your text looking just right with displayio

#

The documentation for add_text() function can be found here: https://docs.circuitpython.org/projects/matrixportal/en/latest/api.html#adafruit_matrixportal.matrixportal.MatrixPortal.add_text

It doesn't seem to specify the X/Y being top left or what. My assumption is either that it will be the top left of the rectangle containing the text, or that it will the the left middle (halfway down on the left side), which is the default x,y positioning on the Label object, although not something people generally assume, so top left would be perhaps in line with expectations so it could have been implemented that way.

#

If your text is static / hardcoded strings I think calling add_text() 3 times is the way to do it.

The multiple x,y pairs in the tuple is for when you are pulling 3 data values out of some dynamically fetched data and putting them onto the screen using the network portion of the helper library.

winged sage
#

Thank you, I have been trying to read all that. But add_text() doesn't seem to actually define what text to display.

neat sedge
#

I see

#

Unfortunately I am personally a lot more familair with the "doing things more manually by making your own labels" route. I'm not sure if I can direct you to the proper way to use the portal library to make multiple static texts. I'll take a look to see what I can come up with though.

winged sage
#

I appreciate your assistance. If it helps, in the future what I really want is for the color of the text to change depending on the status of the door. Green if the door is closed, Red if the door is open.

neat sedge
#

It looks like add_text() has a text parameter.

Try something like:

matrixportal.add_text(
    text_font=terminalio.FONT,
    text="Something here"
    text_position=(2, (matrixportal.graphics.display.height // 2) - 1),
)