Skip to content
← Back to Community
Is it possible to change fonts on pygame?
Profile icon
ETHANSIAO

I've been attempting to successfully change the font for my game in pygame, but it seems that it's not working.

I'm comepletely open to the idea that I'm just not doing it right, so please feel free to give me some pointers regarding how to change fonts successfully.

Thanks!

-E.S.

Voters
Profile icon
AfPython
Profile icon
ETHANSIAO
Comments
hotnewtop
Profile icon
ArchieMaclean

Here is a page about fonts. Remember you can always look stuff up on the internet before posting on a forum :)

Profile icon
ETHANSIAO

@ArchieMaclean Hi, sorry if this question seemed unnecessary. I recently learned you couldn't use pygame audio in repl.it, so I just wanted to be sure that this wasn't the case with fonts as well. Thanks anyways!

Profile icon
ETHANSIAO

@ETHANSIAO Quick follow up: I just now copy-pasted that code on the page you shared with me and ran it on a repl, and sure enough it isn't working. Does this confirm that changing fonts in repl.it isn't possible, or is there something I have to do to make this work? Maybe you could share a repl successfully doing so?

My proof: https://repl.it/@ETHANSIAO/ShowyPuzzlingVirtualmachines

As you can see, the program clearly isn't giving the output intended. What's going on?

Profile icon
ArchieMaclean

@ETHANSIAO The repl gives the right output for me:

This file cannot be displayed: https://storage.googleapis.com/replit/images/1554446953326_7b296b6811f1209675241cd09c8ab235.pn

What is it doing for you?

Profile icon
themaka

@ArchieMaclean Maybe share your repl, so @ETHANSIAO can see what you did differently.

Profile icon
ArchieMaclean

@themaka I didn't do anything differently - I just ran @ETHANSIO's repl :|

Profile icon
ETHANSIAO

@ArchieMaclean that's not the correct font that it was supposed to display.

Try using the comic sans program, and you'll see it doesn't display comic sans either. The following is an image of what the result is supposed to be:
This file cannot be displayed: https://storage.googleapis.com/replit/images/1554490465056_de1c8ebb56611be7fe93c957cf5faa81.pn

This repl that exact same code, but it's still the same default font.
https://repl.it/@ETHANSIAO/Comic-Sans-Tester , and definitely not comic sans, (the image above.) Also notice that it's the result of the repl is the exact same font as what you got, meaning you also got the default text as well, just as I did when I ran that program. What needs to happen for that to change? Or is it simply not possible at the moment?

Profile icon
ArchieMaclean

@ETHANSIAO I looked at the available fonts with

print(pygame.font.get_fonts())

and it appears that repl supports three fonts: dejavuserif, dejavusansmono, dejavusans. So repl doesn't really support fonts, except from these 3, which doesn't give much flexibility.

And I don't know what Comic Sans looks like xD

Profile icon
ETHANSIAO

@ArchieMaclean Hi, thank you so much for the help. In case you're curious, comic sans is shown on the website that you shared with me much earlier. Again, thank you so much for the help, and have a nice day.

Profile icon
ArchieMaclean