我是pygame的新手,我正试图通过按键来改变screen.fill
颜色。我将在下面提供任何帮助/提示的代码将非常感谢。
import pygame
from pygame.locals import *
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
white = (255,255,255)
background_color = (0,0,0,)
(width, height) = (800, 600)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Color Test')
screen.fill(background_color)
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
background_color = white
print('left pressed')
pygame.display.update()
答案 0 :(得分:1)
更改background_color
的值后,您需要填写屏幕。
...
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
background_color = white
print('left pressed')
screen.fill(background_color) #<--- Here
pygame.display.update
...