0
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()

上記のコードはこのエラーを示しています

---------------------------------------------------------------------------
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 画像です。

4

1 に答える 1

4

を呼び出した後、while ループを中断しませんpygame.quit()

使うだけ

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

またはそのようなもの。そうしないと、ループの次の繰り返しでpygame.event.poll() afterを呼び出すことになり、エラーが発生します。 pygame.quit()

于 2013-08-26T07:54:31.920 に答える