【问题标题】:Pygame Error: Video System not Initialized [duplicate]Pygame错误:视频系统未初始化[重复]
【发布时间】:2011-07-30 06:12:50
【问题描述】:

我之前在 python 2.7 中使用过 Pygame,但最近我“升级”到了 python 3.2。我下载并安装了最新版本的 Pygame,据说可以与这个版本的 python 一起使用。然而,我在应该是一个简单的代码块上遇到了这个相当令人沮丧的错误。代码是:

import pygame, random

title = "Hello!"
width = 640
height = 400
pygame.init()
screen = pygame.display.set_mode((width, height))
running = True
clock = pygame.time.Clock()
pygame.display.set_caption(title)

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.quit():
            running = False
        else:
            print(event.type)
    clock.tick(240)
pygame.quit()

我每次运行它都会得到:

17
1
4
Traceback (most recent call last):
  File "C:/Users/David/Desktop/hjdfhksdf.py", line 15, in <module>
    for event in pygame.event.get():
pygame.error: video system not initialized

为什么会出现这个错误?

【问题讨论】:

    标签: python pygame


    【解决方案1】:
    if event.type == pygame.quit():
    

    在上面的行中,您调用的是一个函数pygame.quit(),而您真正想要的是常量pygame.QUIT。通过调用pygame.quit(),pygame 不再被初始化,这就是你得到这个错误的原因。

    因此,将行更改为:

    if event.type == pygame.QUIT: # Note the capitalization
    

    会解决你的问题。

    请注意pygame.quit() 不会退出程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多