python - 即使 pygame 初始化了 "video system not initialized"也会被抛出

标签 python pygame

以下代码会引发错误:

while True:
    event = pygame.event.wait()
    if (event.type == ENDSONG):
            queue_song()

这就是它的内容:

  File "pygametest.py", line 22, in <module>
  event = pygame.event.wait()
  pygame.error: video system not initialized

我所做的大部分挖掘都表明该错误源于 pygame.init() 未运行,但这就是我的代码的启动原因。

我还漏掉了什么吗?

编辑:添加代码。

import pygame
import time

def queue_song():
        print "Queueing New Song"

pygame.init()
pygame.mixer.init()
#rest of code

最佳答案

即使你初始化了Pygame,你也需要调用display.set_mode来避免这个错误:

pygame.init()
pygame.display.set_mode((width, height))
# rest of the code

发生这种情况是因为事件队列需要设置视频模式才能正常工作。来自documentation :

The input queue is heavily dependent on the pygame display module. If the display has not been initialized and a video mode not set, the event queue will not really work.

关于python - 即使 pygame 初始化了 "video system not initialized"也会被抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17202232/

相关文章:

python - 在 Python 中从字符串中获取类型实例

python - 在 VS Code 中使用路径作为参数值设置自定义启动器(Flask - 证书路径)

android - Android 上的 Pygame

python-3.x - Pygame - 使用转义字符或换行符对文本进行 blitting

python - 使用 'Blit' Pygame 无法将图像打印到屏幕

python - 从字典中减去元素

Python node2vec (Gensim Word2Vec) "Process finished with exit code 134 (interrupted by signal 6: SIGABRT)"

python - 如何在 Amazon EMR 上引导安装 Python 模块?

python - 如何在 Pygame 中打印按下控制台的特定键?

python - 如何在 Pygame 中退出全屏模式?