即使pygame初始化了“视频系统未初始化”也会被抛出

2024-10-01 07:12:44 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码引发错误:

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

上面写着:

^{pr2}$

我所做的大部分挖掘工作都说错误源于游戏机初始化()没有运行,但这就是我的代码的开始。在

我还缺什么吗?在

编辑:添加代码。在

import pygame
import time

def queue_song():
        print "Queueing New Song"

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

Tags: 代码importeventtrueifqueuesonginit
1条回答
网友
1楼 · 发布于 2024-10-01 07:12:44

即使初始化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.

相关问题 更多 >