pygame.error: 视频系统未初始化 [英] pygame.error: video system not initialized

查看:348
本文介绍了pygame.error: 视频系统未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我尝试运行我的 pygame 代码时出现此错误:pygame.error: 视频系统未初始化

我在下面的代码中指定翼 IDE 告诉我它的位置

导入操作系统导入系统导入数学导入pygame导入 pygame.mixer从 pygame.locals 导入 *黑色 = 0,0,0白色 = 255,255,255红色 = 255,0,0绿色 = 0,255,0蓝色 = 0,0,255屏幕 = 屏幕宽度,屏幕高度 = 600, 400时钟 = pygame.time.Clock()pygame.display.set_caption("物理")fps_cap = 120运行 = 真在跑步的时候:时钟滴答(fps_cap)对于 pygame.event.get() 中的事件:#error 在这里如果 event.type == pygame.QUIT:运行 = 错误屏幕填充(白色)pygame.display.flip()pygame.quit()系统退出#!/usr/bin/env python

解决方案

您还没有致电 pygame.init() 任何地方.

请参阅基本介绍教程,或特定的导入和初始化教程,其中说明:

<块引用>

在你可以用 pygame 做很多事情之前,你需要初始化它.最常见的方法是拨打一个电话.

pygame.init()

<块引用>

这将尝试为您初始化所有 pygame 模块.并非所有 pygame 模块都需要初始化,但这会自动初始化需要初始化的模块.您还可以轻松地手动初始化每个 pygame 模块.例如,仅初始化您将调用的字体模块.

在您的特定情况下,它可能是 pygame.display 抱怨你调用了它的 set_caption 或者它的 flip 而没有先调用它的 init.但实际上,正如教程所说,最好只init 顶部的所有内容,而不是试图弄清楚什么时候需要初始化.

so I get this error when I try to run my pygame code: pygame.error: video system not initialized

i specify where the wing IDE tells me it is in the code below

import os
import sys
import math
import pygame
import pygame.mixer
from pygame.locals import *

black = 0,0,0
white = 255,255,255
red = 255,0,0
green = 0,255,0
blue = 0,0,255

screen = screen_width, screen_height = 600, 400

clock = pygame.time.Clock()

pygame.display.set_caption("Physics")

fps_cap = 120
running = True
while running:
    clock.tick(fps_cap)

    for event in pygame.event.get(): #error is here
        if event.type == pygame.QUIT:
            running = False

    screen.fill(white)

    pygame.display.flip()

pygame.quit()
sys.exit    
#!/usr/bin/env python

解决方案

You haven't called pygame.init() anywhere.

See the basic Intro tutorial, or the specific Import and Initialize tutorial, which explains:

Before you can do much with pygame, you will need to initialize it. The most common way to do this is just make one call.

pygame.init()

This will attempt to initialize all the pygame modules for you. Not all pygame modules need to be initialized, but this will automatically initialize the ones that do. You can also easily initialize each pygame module by hand. For example to only initialize the font module you would just call.

In your particular case, it's probably pygame.display that's complaining that you called either its set_caption or its flip without calling its init first. But really, as the tutorial says, it's better to just init everything at the top than to try to figure out exactly what needs to be initialized when.

这篇关于pygame.error: 视频系统未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆