import pygame, sys
pygame.init()
screen = pygame.display.set_mode([800,600])
white = [255, 255, 255]
red = [255, 0, 0]
screen.fill(white)
pygame.display.set_caption("My program")
pygame.display.flip()
background = input("What color would you like?: ")
if background == "red":
screen.fill(red)
running = True
while running:
for i in pygame.event.get():
if i.type == pygame.QUIT:
running = False
pygame.quit()
我试图问用户他想要什么样的背景颜色。如果用户写红色,颜色不会改变,并仍然保持白色。Pygame:如何更改背景颜色
请包含一个可运行的样本。你粘贴的内容不是语法上有效的Python,并且会在运行时出错。 – mwchase
由于缩进不正确(在'if i.type == pygame.QUIT:'后面),代码的末尾似乎存在转录错误。 – e0k
pygame在缓冲区中绘制并且'pygame.display.flip()'在监视器上发送缓冲区。 – furas