以下代码会引发错误:
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/