Pygame error : video system not initialized [duplicate]

限于喜欢 提交于 2021-01-20 13:01:47

问题


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

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


回答1:


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

Just use

while 1:
    ev = pygame.event.poll() 
    if ev.type == pygame.QUIT:
        break
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.



来源:https://stackoverflow.com/questions/18434981/pygame-error-video-system-not-initialized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!