【问题标题】:pygame.init error: video system not initializedpygame.init 错误:视频系统未初始化
【发布时间】:2017-09-25 09:08:52
【问题描述】:

我正在编写一个 pygame 项目,我会告诉你...

import pygame
pygame.init()

WHITE = (255, 255, 255)
pad_width = 1024
pad_height = 512

def runGame():
   global gamepad, clock

crashed = False
while not crashed:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        gamepad.fill(WHITE)
        pygame.display.update()
        clock.tick(60)

    pygame.quit()


def initGame():
    global gamepad, clock

    pygame.init()
    gamepad = pygame.display.set_mode((pad_width, pad_height))
    pygame.display.set_caption('Pyflying')

    clock = pygame.time.Clock()
    runGame()


initGame()        

这是代码,现在是错误....

Traceback (most recent call last):
 File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 36, in <module>
   initGame()
 File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 33, in initGame
   runGame()
 File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 14, in runGame
   for event in pygame.event.get():
pygame.error: video system not initialized

我不知道如何编程......如果你知道错误,请回答! 而且,我是 pygame 的新手.... ㅠ.ㅠ 如果您知道如何使用 pygame,请告诉我!谢谢……

【问题讨论】:

    标签: python pygame


    【解决方案1】:

    你的缩进是错误的,解决这个问题:

    def runGame():
        global gamepad, clock
    
        crashed = False
        while not crashed:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    crashed = True
    
                gamepad.fill(WHITE)
                pygame.display.update()
                clock.tick(60)
    
          # pygame.quit() Remove this line, it shouldn't be in a loop or just break after it's executed
    

    【讨论】:

    • 哦,那你必须删除pygame.quit()。放错地方了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多