我试图使用 pygame 创建一个单击运行时的脚本。窗口将屏幕的颜色更改为蓝色、灰色、红色,它们之间有一秒的延迟,然后退出该循环,然后按照正常的print("cycle done")
代码运行游戏。不幸的是,窗口打开,挂起大约 3 秒钟,然后显示红色屏幕,而不是通过每种颜色。
import pygame as pg
running = True
calibration = False
pg.init()
screen = pg.display.set_mode((600, 400))
screen_rect = screen.get_rect()
clock = pg.time.Clock()
timer = 0
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if not calibration:
pg.time.wait(1000)
screen.fill(blue)
pg.display.flip()
pg.time.wait(1000)
screen.fill(green)
pg.display.flip()
pg.time.wait(1000)
screen.fill(red)
pg.display.flip()
calibration = True
print(calibration)
print("cycle done")
clock.tick(60)