0

I was trying to load a font in pygame to render some simple text. I tried importing a font I had downloaded. The font is named hack.tff, and it's in assets/fonts/.

hack = pygame.font.Font('assets/fonts/hack.tff', 30)

But, strangely, when running the code, it returns a error: FileNotFoundError: [Errno 2] No such file or directory.

I ran the code through cmd and opening the .py file. The cmd is on the same directory as the .py file

Pietro
  • 5
  • 2
  • 1
    I suspect the working directory from where you launch your application isn't what you think it is. Relative paths will be relative to the current working directory. You may want to expand this question with how your are launching the program. – Mikael Öhman Mar 31 '21 at 00:57
  • I tried both cmd (I am on the game dir) and opening the .py file directly. – Pietro Mar 31 '21 at 00:58
  • Ttf vs tff? I think you had the extension wrong. – Starbuck5 Mar 31 '21 at 01:44

1 Answers1

0

You might try './assets/fonts/hack.tff' or a complete path name such as, os.path.abspath( './assets/fonts/hack.tff' )

Derek
  • 1,916
  • 2
  • 5
  • 15