Search code examples
pygame

How to change font object size in pygame


I have these code

FONT = pygame.font.Font("font/calibri.ttf", 50)
FONT.size = 25

but the compilter say

AttributeError: 'pygame.font.FONT' object attribute 'size' is read-only

I see no method help me change size. How can I do that?


Solution

  • You can't change the size of an existing Font object. You have to create a new Font object with the size you want.


    An alternative is the newer freetype module. The render methods of the Font class in this module support text rendering using a different size.