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