我有一个问题,我希望今天有人能帮助我,如果你能的话,请按照我被困住的方式去做,这里的文章告诉我,我被告知的错误应该有效。我正在使用 IntelliJ 的 PyCharm 和最新版本的 python - 3.8.5 所以我的目标是让我的 PyGame 窗口变成白色,因为在启动时它是黑色的,所以当我输入以下代码时会出现这个错误:
import pygame
# Initialise the pygame functions#
pygame.init()
# Create the screen for the user#
root = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Space Invaders")
icon = pygame.image.load("space.png")
pygame.display.set_icon(icon)
# Makes the pygame window appear for longer than a few milliseconds#
runtime = True
while runtime:
for event in pygame.event.get():
if event.type == pygame.QUIT:
runtime = False
screen.fill(255, 255, 255) #The error appears here and I cant find out why because I have looked at articles and they say this should work#
pygame.display.update()
PyCharm 的响应是:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:/Users/doesnotcompute10/OneDrive/Main Doccuments/Personal/Code/Code.PythonPycharm/PyGame/Learning/Space Invaders.py", line 25, in <module>
screen.fill(255, 255, 255)
NameError: name 'screen' is not defined
Process finished with exit code 1
如果有人知道如何解决,请回复和/或发送电子邮件至 doesnotcompute10@outlook.com
相关分类