[英]Why does my window keep flashing in pygame?
我在 pygame 中创建了一个窗口,试图将窗口设为白色,即使我只调用 pygame.display.update() 一旦它在白色和黑色之间闪烁。
这是我的代码:
import pygame
running = True
pygame.init()
White = (255, 255, 255)
while running == True:
screen = pygame.display.set_mode((1400, 800))
screen.fill(White)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
我尝试将其更改为 pygame.display.flip() 但它仍然保持不变。 我还尝试将 pygame.display.update() 置于循环之外,但随后屏幕保持黑色。
您需要在应用程序循环之前创建一次 Pygame 窗口 ( pygame.display.set_mode
),而不是在应用程序循环中不断创建一个新窗口:
import pygame
running = True
pygame.init()
screen = pygame.display.set_mode((1400, 800))
White = (255, 255, 255)
while running == True:
screen.fill(White)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.