为了账号安全,请及时绑定邮箱和手机立即绑定

Python 中的 screen.fill() 命令不起作用

Python 中的 screen.fill() 命令不起作用

繁花如伊 2023-03-30 10:21:37
我有一个问题,我希望今天有人能帮助我,如果你能的话,请按照我被困住的方式去做,这里的文章告诉我,我被告知的错误应该有效。我正在使用 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 = Truewhile 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.6Hello from the pygame community. https://www.pygame.org/contribute.htmlTraceback (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 definedProcess finished with exit code 1如果有人知道如何解决,请回复和/或发送电子邮件至 doesnotcompute10@outlook.com
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 47 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信