【发布时间】:2020-08-24 07:24:59
【问题描述】:
我试图使用 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)
【问题讨论】:
-
嗯,在我的机器上运行良好。预期输出为蓝色 1 秒,绿色 1 秒,然后保持红色?
-
是的,这正是我想要发生的事情,我使用的是 Mac,我可以知道你正在运行它吗?
-
我在 Windows 10 上运行它并使用 pygame 1.9.6
-
我使用相同版本的 pygame。那么知道是什么导致了这个问题吗?
-
这样的东西可能会起作用:[...]
if not calibration:pg.time.wait(1000)screen.fill(blue)pg.display.flip()pg.event.pump()pg.time.wait(1000)screen.fill(green)pg.event.pump()@98 987654333@pg.display.flip()pg.event.pump()calibration = Trueprint(calibration)
标签: python pygame pygame-clock