akozi
akozi

Reputation: 455

Python/Pygame importing fonts trouble

I'm trying to use a font in a game I'm trying to build. The font name is SansitaOne. Unfortunately pygame doesn't let me import it.

pygame.font.init()
myfont = pygame.font.Font("incAssests/fonts/SansitaOne.tff",25)

The error I get is: IOError: unable to read font filename eventhough I've checked numerous times that that is the correct directory.

As well, the example given to me is.

font = pygame.font.Font("myresources/fonts/Papyrus.ttf", 26)

Any help is appreciated. I'll just be doing more productive things meanwhile.

Upvotes: 1

Views: 11899

Answers (1)

user4435153
user4435153

Reputation:

You could use myfont = pygame.font.SysFont("SansitaOne.tff",25) instead.SysFont doesn't require whole path.But be sure your font is in the Windows font directory.Also you should write pygame.init() not that one, font.init is not necessary.

To install a font

Open Fonts by clicking the Start button Picture of the Start button, clicking Control Panel, clicking Appearance and Personalization, and then clicking Fonts.

Then drag your font to there. That's all.

You should see this screen, drag your font here.

enter image description here

Upvotes: 4

Related Questions