Why doesn't keypresses work in my code( pygame?) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't keypresses work in my code( pygame?)

I don't know why don't keypresses work in pygame. If anybody knows please explain. Here is my code. import pygame pygame.init() white = (255, 255, 255) green = (0, 255, 0) blue = (0, 0, 128) black = (0, 0, 0) red = (255, 0, 0) w = 500 h = 500 x = 15 y = 480 vel = 5 screen = pygame.display.set_mode((w, h)) square = pygame.image.load(r'/Users/lanik2009/Downloads/square.PNG') square = pygame.transform.scale(square, (46, 40)) triangle = pygame.image.load(r'/Users/lanik2009/Downloads/triangle.PNG') triangle = pygame.transform.scale(triangle, (46, 40)) def player(): screen.fill(black) pygame.draw.circle(screen,white, (15, 480), 10, 500) screen.blit(triangle, (80, 460)) screen.blit(square, (180, 460)) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False userInput = pygame.key.get_pressed() if userInput[pygame.K_LEFT]: x = -vel if userInput[pygame.K_RIGHT]: x = vel player() pygame.display.update()

10th May 2021, 1:47 AM
Ailana
Ailana - avatar
1 Answer
0
We can't read your code. That's not a way to link code in Q&A section. For details on how to share codes, check this: https://www.sololearn.com/post/75089/?ref=app
10th May 2021, 5:43 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar