V
V
Vova05052021-03-16 00:01:32
Python
Vova0505, 2021-03-16 00:01:32

Error in code: AttributeError: 'NoneType' object has no attribute 'fill'?

import pygame
import time

pygame.init()
win = pygame.display.set_caption("123")
x = 50
y = 50
widht = 40
height = 60
speed = 5

run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= speed
if keys[pygame. K_RIGHT]:
x -= speed
if keys[pygame.K_UP]:
x -= speed
if keys[pygame.K_DOWN]:
x -= speed
win.fill((0,0,0))
pygame.draw.rect(win, (0,0,255), (x,y,height))
pygame.display.update()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-03-16
@Vova0505

You assign neither:

win = pygame.display.set_mode((w, h))
win_cap = pygame.display.set_caption("123")

ps: when posting code - use the appropriate tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question