Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame错误:视频系统未初始化_Python_Pygame - Fatal编程技术网

Python Pygame错误:视频系统未初始化

Python Pygame错误:视频系统未初始化,python,pygame,Python,Pygame,我以前曾将Pygame与Python2.7结合使用,但最近我“升级”到了Python3.2。我下载并安装了Pygame的最新版本,据说它可以与这个版本的python一起工作。然而,我在一个简单的代码块上遇到了这个相当令人沮丧的错误。代码是: import pygame, random title = "Hello!" width = 640 height = 400 pygame.init() screen = pygame.display.set_mode((width, height))

我以前曾将Pygame与Python2.7结合使用,但最近我“升级”到了Python3.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
17
1.
4.
回溯(最近一次呼叫最后一次):
文件“C:/Users/David/Desktop/hjdfhksdf.py”,第15行,在
对于pygame.event.get()中的事件:
pygame.error:视频系统未初始化
为什么我会犯这个错误

if event.type == pygame.quit():
在上面的一行中,您正在调用函数
pygame.quit()
,而您真正需要的是常量
pygame.quit
。通过调用
pygame.quit()
,pygame不再初始化,这就是为什么会出现该错误

因此,将行更改为:

if event.type == pygame.QUIT: # Note the capitalization
这会解决你的问题

需要注意的是,
pygame.quit()
不会退出程序