Error message when using PFont

So I wanted to add another font to my python project, but I keep getting an error message for the PFont line. Here is my code:

def setup():
    size(1600, 900)
    PFont headerFont    # Error message: Maybe there's an unclosed paren or quote mark somewhere before this line?
    headerFont = loadFont("BlackBubbleFont.vlw")

I’ve already went to Tools > Create Font to add my font “BlackBubbleFont.vlw” and it is in my project’s data folder. I’ve also tried putting the “PFont headerFont” line above def setup(), but the error message still pops up.

I followed a youtube tutorial exactly, so I’m not sure why mine doesn’t work. The only difference I can think of is that I’m using the python mode, while the youtuber was using java.

Is there something I did wrong? Thanks!

1 Like

Have you tried just to load the TTF/OTF font file directly (no Create Font step required)? Place the TTF/OTF in the sketch’s data sub-folder, and use some code like this –

def setup():
    size(1600, 900)
    headerFont = createFont(′BlackBubbleFont.ttf′, 20)
2 Likes

Remember you are in Python, so no such thing as variable declaration PFont headerFont!
See if this makes any sense:

def setup():
    size(1600, 900)
    global headerFont    # if you want to use the variable inside draw()
    headerFont = loadFont("BlackBubbleFont.vlw")
3 Likes