Pygame mainloop qiuting异常处理

问题描述

嗨,我正在编写一个简单的国际象棋程序,不幸的是,我遇到了一些意想不到的问题。在添加了一个跟踪所有图形位置的列表之后,我无法使用到目前为止使用的方法关闭该窗口。原来是

  for event in pygame.event.get():
    # print(event)
    # Checking if the user clicks the red quit cross
    if event.type == pygame.QUIT:
        # run control the mainloop,wheather True or not 
        run = False

添加列表后,此操作停止了,因此我现在使用:

for event in pygame.event.get():
    # print(event)
    if event.type == pygame.QUIT:
        pygame.display.quit()
        pygame.quit()

我尝试添加一些异常处理:

try:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit()
except pygame.error():
    print('Program closed')

但是未达到except语句并显示错误:(pygame.error:视频系统未初始化)

能否请您告诉我如何正确处理此异常,或者提出另一种制动主回路的方法。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)