pygame.error: video system not initialized

后端 未结 8 1213
情深已故
情深已故 2020-12-11 05:42

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

相关标签:
8条回答
  • 2020-12-11 06:09

    If you using class for your pygame window don't use pygame.init() in your class. Use pygame.init() at bottom the libraries.

    0 讨论(0)
  • 2020-12-11 06:11

    I had this issue recently, and I discovered a strange and unusual bug in the code that I'd written -- only after reading it and re-reading it a dozen times over a 10 minute stretch, trying to launch the file (which looked perfect) a dozen times.

    There was pygame.init(). There was screen = pygame.display.set_mode((size)) with the variable size in position to be available in the global namespace.

    Turns out it was the main game loop.

    # main game loop
    while RUNNING == True:
        for tneve in pygame.event.get():
            if tneve.type == QUIT:
                print(tneve)
                RUNNING = False
            loop()
            render()
            CLOCK.tick(FPS)
        cleanup()
    # End
    

    What a pain!

    P.S. The problem is the one-stop-too-far indentation of everything below RUNNING = False.

    0 讨论(0)
  • 2020-12-11 06:17

    I made some modifications to your code:

    import os
    import sys
    import math
    import pygame
    import pygame.mixer
    from pygame.locals import *
    
    pygame.init()
    black = 0, 0, 0
    white = 255, 255, 255
    red = 255, 0, 0
    green = 0, 255, 0
    blue = 0, 0, 255
    
    screen = pygame.display.set_mode((600, 400))
    
    clock = pygame.time.Clock()
    
    pygame.display.set_caption("Physics")
    
    
    while True:
        clock.tick(120)
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
        screen.fill(green)
    
        pygame.display.flip()
    
    0 讨论(0)
  • 2020-12-11 06:19

    You have to add:

    pygame.init()
    

    Before you quit the display you should stop the while loop.

    0 讨论(0)
  • 2020-12-11 06:26

    You get an error because you try to set the window title (with set_caption()) but you haven't created a pygame window, so your screen variable is just a tuple containing the size of your future window.

    To create a pygame window, you have to call pygame.display.set_mode(windowSize).

    Good luck :)

    0 讨论(0)
  • 2020-12-11 06:26

    1 this problem happens when you using a beta version.

    2 so my suggestion is please use the new, old version(If now lunch 3.8 python, you need to install python 3.7)

    3 Now goto python terminal and install pygame (pip install pygame)

    4 now the problem is solved...

    0 讨论(0)
提交回复
热议问题