1
\$\begingroup\$

I always get the error message "video system not initialized"

I don't get where I went wrong with the code below:

import pygame
pygame.init()

display_width = 800
display_height = 600

gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('4 pics 1 word: ASTRONOMY VERSION')

black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

answered = False
satImg1 = pygame.image.load(r'C:\Users\andrea\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.7\img\satellite.png')

def satImg(x,y):
    gameDisplay.blit(satImg1,(x,y))

x = (display_width * 1.0)
y = (display_height * 1.5)

while not answered:
    if pygame.mixer.get_busy() != None:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                answered = True         
    gameDisplay.fill(white)
    satImg1 = (x, y)
    pygame.quit()
    quit()
\$\endgroup\$
2
  • \$\begingroup\$ When asking questions here, please take the time to ensure your code is formatted legibly and your issue is fully explained. Consult the help center if you have trouble with formatting. I've edited your question to clean it up, but it would still benefit from more text description of what you're trying to do, and how you've tried solving this problem so far. \$\endgroup\$
    – DMGregory
    Feb 25, 2019 at 15:50
  • \$\begingroup\$ It seems to be a bad identation in the last lines, maybe quit() calls should be out of the while loop \$\endgroup\$
    – Juanpa
    Mar 1, 2019 at 1:27

2 Answers 2

1
\$\begingroup\$

As Juanpa already implied in a comment, you get the error because you call the quit() function, which in turn makes the pygame module unusable, and your code should look like this:

...
while not answered:
    if pygame.mixer.get_busy() != None:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                answered = True         
    gameDisplay.fill(white)
    satImg1 = (x, y)
pygame.quit()
\$\endgroup\$
0
\$\begingroup\$

you quit inside the loop instead of outside so it will immediately remove pygame

so move pygame.quit() and quit() outside the loop

\$\endgroup\$
2
  • \$\begingroup\$ This seems to be the same fix proposed by user sloth three years ago. Is there something new you want to suggest here, that's not covered by the existing answer? \$\endgroup\$
    – DMGregory
    Apr 29, 2022 at 18:44
  • \$\begingroup\$ This answer was flagged as low-quality because of its length and content & placed in the low quality review queue. I'm not voting to recommend deletion as this looks like an attempt to answer the question, however this answer isn't particularly useful either - it repeats information that's already covered in another answer & doesn't provide anything of additional benefit. \$\endgroup\$
    – Pikalek
    May 4, 2022 at 0:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .