我有一个问题,我希望今天有人能帮助我,如果你可以的话,请按照我的想法去做,这里的文章告诉我,我被告知的是错误的,应该有效。我正在使用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
开始编码强>
有两个问题。显示器的名称^{} 是} 的第一个参数是颜色(参见Receiving ValueError: invalid recstyle object)。因此,必须传递包含3个组件而不是3个参数的元组:
root
,而不是screen
。此外^{screen.fill(255, 255, 255)
相关问题 更多 >
编程相关推荐