Pygame 错误:视频系统未初始化 [英] Pygame error : video system not initialized

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

问题描述

import sys,pygame
pygame.init()

size = width , height = 600,400 
screen = pygame.display.set_mode(size)

tux = pygame.image.load("tux.png")

screen.blit(tux,(200,200))
screen.blit(tux,(0,0))
pygame.display.flip()

while 1:
ev = pygame.event.poll() 
if ev.type == pygame.QUIT:
    pygame.quit()

上面的代码显示了这个错误

The above code is showing this error

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
C:\Anaconda\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
    169             else:
    170                 filename = fname
--> 171             exec compile(scripttext, filename, 'exec') in glob, loc
    172     else:
    173         def execfile(fname, *where):

C:\Users\digi.abhshk\Desktop\tux.py in <module>()
    11 pygame.display.flip()
    12 while 1:
--->13         ev = pygame.event.poll()
    14         if ev.type == pygame.QUIT:
    15             pygame.quit()

error: video system not initialized

我对 pygame 很陌生,这是什么错误以及如何删除它?PS:tux 是我在这个文件中使用的 png 图像

I am very new to pygame , what is this error and how to remove it ? PS: tux is the png image i am using in this file

推荐答案

在调用 pygame.quit() 后,您不会中断 while 循环.

You don't break your while loop after calling pygame.quit().

只要使用

while 1:
    ev = pygame.event.poll() 
    if ev.type == pygame.QUIT:
        break
pygame.quit()

或者类似的东西.否则,您将在循环的下一次迭代中调用 pygame.event.poll() after pygame.quit() ,这将导致你的错误.

or something like that. Otherwise, you'll call pygame.event.poll() after pygame.quit() on the next iteration of the loop, which will lead to your error.

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

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