[英]pygame window keeps not responding
长时间尝试安装2.7的pygame之后,终于安装好了,现在我已经下载了它,但是现在存在的问题是,在打开几秒钟后,它仍然没有响应。 任何答案将不胜感激,到目前为止我所拥有的代码仅仅是。
import pygame
pygame.init()
pygame.display.set_mode((640,480))
所以我需要一些帮助。
因此,您想要做的事,就像skrx所说的那样,是一个while循环,以使代码连续地保持在while
循环和pygame窗口内,并保持for
循环,以便能够关闭窗口。 您可以按照以下方法进行操作:
import pygame
pygame.init()
pygame.display.set_mode((640, 480)) # opens the display
while True: # the while loop that will keep your display up and running!
for event in pygame.event.get(): # the for event loop, keeping track of events,
if event.type == pygame.QUIT: # and in this case, it will be keeping track of pygame.QUIT, which is the X or the top right
pygame.quit() # stops pygame
还有其他方法可以停止while循环,您可以这样做:
running = True
while running: # the while loop that will keep your display up and running!
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.