Pygame font error

后端 未结 3 1096
情深已故
情深已故 2021-01-04 08:06

So I decided to start making a game and I was testing it a bit and then I got this error:

Traceback (most recent call last):
  File \"TheAviGame.py\", line          


        
相关标签:
3条回答
  • 2021-01-04 08:38

    You put None in the font:

    font = pygame.font.Font(None, 25)
    

    You can’t do that. You have to put a type of font there.

    And you should call pygame.init().

    0 讨论(0)
  • 2021-01-04 08:42

    In order to use some pygame modules, either pygame or that specific module has to be initialised before you start using them - this is what the error message is telling you.

    To initialize pygame:

    import pygame
    ...
    pygame.init()
    

    To initialize a specific library (eg font):

    import pygame
    ...
    pygame.font.init()
    

    In most cases, you will want to initialise all of pygame, so use the first version. In general, I would place this at the top of my code, just after importing pygame

    0 讨论(0)
  • 2021-01-04 08:46

    You never initialized pygame and pygame.font after importing:

    # imports
    
    pygame.init() # now use display and fonts
    
    0 讨论(0)
提交回复
热议问题