pygame窗口一直没有响应

时间:2018-05-13 16:14:51

标签: python pygame

经过很长一段时间尝试安装pygame for 2.7它终于安装了,我现在已经下载了,但现在有一个问题,它在打开几秒后仍然没有响应。任何答案将不胜感激,我到目前为止的代码只是。

import pygame

pygame.init()

pygame.display.set_mode((640,480))

所以我需要一些帮助。

1 个答案:

答案 0 :(得分:1)

所以你想要做什么,比如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()

希望这有帮助!