python - 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:>
- 我通过运行安装了 pygame: pip install pygame
即使是像下面这样非常短的代码也不适用于我,:
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
我很抱歉问,因为我知道这肯定是不可重现的,因为这不是代码的问题。我是否缺少安装任何东西?
解决方案
推荐阅读
- sharepoint - 仅在文件夹而非文档上实施元数据
- javascript - 显示该成员是否有 nitro discord
- python - 将“n”行合并为 1 行的数据框列的条件聚合
- dart - 是否有 Dart Linter 规则强制字段返回类型和方法参数?
- php - Laravel/Angular“密码过期”身份验证流程
- amazon-web-services - 使用 aws cli 创建 cognito-user-pool 时出现“未知选项”错误
- python - 如何创建一个可下标的 Mock 对象?
- python - 不和谐.py | 删除空的语音通道
- oracle-sqldeveloper - Oracle SQL Developer 中的突然导出失败
- python - TypeError: 'int' 对象在渲染 Flask 模板时不可迭代