首页 > 解决方案 > pygame.init() 终止程序没有错误

问题描述

摘要:当我运行代码 pygame.init() 时,它会终止程序,没有错误。

我尝试在 init() 之前和之后调用 print(),并且 init() 之后的 print 语句(以及此行之外的任何其他代码)被忽略并终止。

我以为我的 python 版本有问题,所以我尝试了 3.6.0 和 3.7.4,都遇到了同样的问题。我也尝试过将整个代码包装在 try/catch 中,但没有捕获任何内容。

真正奇怪的一件事是,当我在命令行中运行这些代码时(通过键入 py),在运行 init() 之后,控制台从 python 中退出。

C:>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.get_init()
False
>>> pygame.init()
C:>

即使是像下面这样非常短的代码也不适用于我,:

import pygame
pygame.init()
pygame.quit()

但我放了一些测试代码来看看发生了什么。这是我做的非常简单的测试:

import pygame

def testFunct():
    print('successfully quit')
pygame.register_quit(testFunct) #this should print when pygame quits

print(pygame.get_init())        #False
pygame.init()                   #program stops here for few seconds, then terminates
print('initialization done')    #this line is ignored
pygame.quit()                   #quit message is not printed

结果如下:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
False

我很抱歉问,因为我知道这肯定是不可重现的,因为这不是代码的问题。我是否缺少安装任何东西?

标签: pythonpygame

解决方案


推荐阅读