0

So I'm just trying to make a guide for my game. This is my code so far. This code is incomplete

import pygame
import sys
pygame.init()
myfont = pygame.font.SysFont("Phosphate, 14")
keys=pygame.key.get_pressed()
while True:
    for even in pygame.event.get():
        if keys[pygame.K_K]:
            if keys[pygame.K_K] and keypressed:
                keypressed = label = myfont.render("Guide.md", 1, (255,255,0))
        screen.blit(label, (100,100))
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit

What am I doing wrong? When I try to run the code it says: File"(My user, I didn't put it for saftey reasons)", line 4, in myfont = pygame.font.SysFont.size("Phosphate,14") AttributeError: 'function' object has no attribute 'size'

  • 1
    You say you get an error that mentions `line 4, in my font = pygame.font.SysFont.size("Phosphate,14")`, yet the code you posted does not do `pygame.font.SysFont.size("Phosphate,14")`. Why is that? – Bryan Oakley Jan 03 '22 at 05:29
  • 1
    Line 4 in your question does not match line 4 in your code block. So which actually is the offending code? Maybe you want to say `SysFont("Phosphate, 14").size` rather than `SysFont.size("Phosphate 14")`? – Daniel Junglas Jan 03 '22 at 05:29
  • @DanielJunglas The offending code is line 4. It says that (even if I try your simple fix) that missing 1 required positional argument: 'size' – Joonseo Lee Jan 03 '22 at 05:33
  • Please check the documentation for the `SysFont` function: https://www.pygame.org/docs/ref/font.html#pygame.font.SysFont. You have to provide the font file name and size as separate arguments. – Daniel Junglas Jan 03 '22 at 05:35
  • So something like this? pygame.font.Font.size("14") pygame.font.SysFont("Phosphate") – Joonseo Lee Jan 03 '22 at 05:38
  • It is a typo. It has to be `myfont = pygame.font.SysFont("Phosphate", 14)` instead of `myfont = pygame.font.SysFont("Phosphate, 14")`. [`SysFont`](https://www.pygame.org/docs/ref/font.html#pygame.font.SysFont) has 2 arguments, the font name and the size. – Rabbid76 Jan 03 '22 at 07:05

0 Answers0