【问题标题】:pygame window keeps not respondingpygame窗口一直没有响应
【发布时间】:2018-05-13 16:14:50
【问题描述】:

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

import pygame

pygame.init()

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

所以我需要一些帮助。

【问题讨论】:

标签: python pygame


【解决方案1】:

所以你想要做的,就像 skrx 所说的那样,是一个 while 循环,以持续将代码保持在 while 循环和 pygame 窗口运行,以及一个 @987654322 @事件循环,以便能够关闭窗口。你可以这样做:

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()

希望这会有所帮助!

【讨论】:

  • 我现在可以继续使用 pygame 而不会崩溃。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-08
  • 2022-12-12
相关资源
最近更新 更多