python - Pygame 中的表面颜色仅在窗口关闭后才会改变

标签 python pygame

我是 Pygame 的新手,看过一些游戏的教程。我遇到的问题是,除非我关闭 window ,否则表面颜色不会改变。我见过很多人在游戏循环中将填充放在下面,背景颜色立即改变,但就我而言,它保持黑色,直到我按下关闭按钮。然后它改变颜色并退出。

import pygame
pygame.init()
blue=(0,0,255)
screen=pygame.display.set_mode((500,500))
pygame.display.set_caption('virus')
icon= pygame.image.load('virus-face.png')
pygame.display.set_icon(icon)

running=True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running=False
screen.fill(blue)

pygame.display.update()
pygame.quit()

最佳答案

这是Indentation的问题.
screen.fill(blue)screen.fill(blue) 必须在应用程序循环中完成:

running=True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running=False

    screen.fill(blue)
    pygame.display.update()

pygame.quit()

关于python - Pygame 中的表面颜色仅在窗口关闭后才会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58964238/

相关文章:

python - 让docker镜像与宿主机环境交互

python - 如何在 pygame 中限制调整窗口大小

python - Pygame (python) 中翻转图像的问题

python - Pygame screen.blit() 来自非零 y 坐标

python - 如何使用 Flask-ReSTLess 启用 CORS

python - 从子进程开始时出现 EOFError

python - 在 Tkinter 文本框中突出显示两个 xml 文件之间的差异

python - 带有redis的 celery 中的任务优先级

python - 无法安装pygame

Python - 让我的宇宙飞船朝其面向的方向射击第 2 部分