I was following a tutorial on pygame introduction, following his code exactly, but for some reason, when I got to the section which monitored key presses and moved the player accordingly, it claimed that pygame does not have ‘K’ attribute. Again, I triple checked that my code is exactly the same as his.
import pygame
pygame.init()
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
player = pygame.Rect((300, 250, 50, 50))
run = True
while run:
pygame.draw.rect(screen, (255, 0, 0), player)
key = pygame.key.get_pressed()
if key[pygame.K.a] == True: #Here, it claims that pygame does not have 'K' attribute
player.move_ip(-1, 0)
elif key[pygame.K.d] == True:
player.move_ip(1, 0)
elif key[pygame.K.w] == True:
player.move_ip(0, 1)
elif key[pygame.K.s] == True:
player.move_ip(0, -1)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()