Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:37:09+00:00 2026-06-02T09:37:09+00:00

I don’t seem to able to get rid of this error, when I try

  • 0

I don’t seem to able to get rid of this error, when I try to exist the game. the game runs fine but only get the error when I try to exist the game.

import pygame
from pygame import *
import random
import time
import os
import sys
from pygame.locals import *


black = (0,0,0)
white = (255,255,255)

pygame.init()

def game():

 os.environ['SDL_VIDEO_CENTERED'] = '1'
 mouse.set_visible(False)

#screen
screen_width = 800
screen_height = 500
screen = pygame.display.set_mode([screen_width,screen_height])
#load images etc.
backdrop = pygame.image.load('bg.jpg').convert_alpha()
menu = pygame.image.load('green.jpg').convert_alpha()
ballpic = pygame.image.load('ball.gif').convert_alpha()
mouseball = pygame.image.load('mouseball.gif').convert_alpha()
display.set_caption('Twerk')
back = pygame.Surface(screen.get_size())

def text(text,x_pos,color,font2=28):
    tfont = pygame.font.Font(None, font2)

    text=tfont.render(text, True, color)
    textpos = text.get_rect(centerx=back.get_width()/2)
    textpos.top = x_pos
    screen.blit(text, textpos)

start = False
repeat = False
while start == False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            start = True
            #falling = True
            #finish = True

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                start = True
    #game over screen
    screen.blit(menu,[0,0])
    pygame.display.set_caption("TWERK")

    #Text
    #"Welcome to Escape"
    #needs replacing with logo 
    text("Twerk",60,white,300)

    #"Instructions"
    text("Instructions",310,white)
    text("----------------------------------------------------------------------------------------",320,white)
    text("Avoid the the enemies",340,white)
    text("Last as long as you can!",360,white)
    text("Press space to start",420,white)
    pygame.display.flip()


while start == True:
positionx=[]
positiony=[]
positionxmove=[]
positionymove=[]
falling = False
finish = False
score=0
enemies=4
velocity=1

for i in range(enemies):
  positionx.append(random.randint(300,400)+random.randint(-300,200))
  positiony.append(random.randint(200,340)+random.randint(-200,100))
  positionxmove.append(random.randint(1,velocity))
  positionymove.append(random.randint(1,velocity))


font = pygame.font.Font(None, 28)
text = font.render('Starting Twerk... ', True, (100,100,100))
textRect = text.get_rect()
textRect.centerx = screen.get_rect().centerx
textRect.centery = screen.get_rect().centery

screen.blit(backdrop, (0,0))
screen.blit(text, textRect)
pygame.display.update()
game=time.localtime()

while start == True:
  end=time.localtime()
  score= (end[1]-game[1])*3600 + (end[4]-game[4])*60 + end[5]-game[5]
  if score > 1: break

first=True
strtTime=time.localtime()

while not finish or falling:
  screen.blit(backdrop, (0,0))
  for i in range(enemies):
    screen.blit(ballpic,(positionx[i],positiony[i]))
    (mousex,mousey)=mouse.get_pos()
    screen.blit(mouseball,(mousex,mousey))
    display.update()
    strt = time.localtime()

  if first:
    while True:
      end=time.localtime()
      score= (end[3]-strt[3])*3600 + (end[4]-strt[4])*60 + end[5]-strt[5]
      if score > 3: break
    first = False

  if falling:
    for i in range(enemies):
      positionymove[i]=1000
      positionxmove[i]=0


  for i in range(enemies): positionx[i]=positionx[i]+positionxmove[i]
  for i in range(enemies): positiony[i]=min(600,positiony[i]+positionymove[i])

  if falling:
    falling=False
    for posy in positiony:
      if posy<600: falling=True


  if not falling:
    for i in range(enemies):
      for j in range(i+1,enemies):
        if abs(positionx[i]-positionx[j])<20 and abs(positiony[i]-positiony[j])<20:
          temp=positionxmove[i]
          positionxmove[i]=positionxmove[j]
          positionxmove[j]=temp
          temp=positionymove[i]
          positionymove[i]=positionymove[j]
          positionymove[j]=temp

    for i in range(enemies):  
      if positionx[i]>600: positionxmove[i]*=-1
      if positionx[i]<0: positionxmove[i]*=-1
      if positiony[i]>440: positionymove[i]*=-1
      if positiony[i]<0: positionymove[i]*=-1

    for i in range(enemies):
      if abs(positionx[i]-mousex)<40 and abs(positiony[i]-mousey)<40:
        falling = True
        finish = True
        #start = False
        endTime=time.localtime()
        score= (endTime[3]-strtTime[3])*3600 + (endTime[4]-strtTime[4])*60 + endTime[5]-strtTime[5]
        break

      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          pygame.quit()

          if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
              pygame.quit()




game()

This is the error I get, I’ve changed quit() to QUIT but still no luck.

Traceback (most recent call last):
File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 171, in <module>
 game()
File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 160, in game
 for event in pygame.event.get():
 pygame.error: video system not initialized

thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:37:10+00:00Added an answer on June 2, 2026 at 9:37 am

    You should stop your main loop when you want to exit the game.

    My suggestions, either of

    • call exit() after pygame.quit()
    • set finish = True and start = False (though due to some indentation issues with your pasted code it’s not possible to tell that this would actually work)

    You should call pygame.quit() only when you want to terminate your Python session.

    My suggestion: if you want to call game() more than once, e.g. in an interactive session, you should remove the call to pygame.quit() inside game(). This function uninitializes pygame and naturally all attempts to call its functionality will fail then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what it is, but I can't seem to figure this out
I don't know whether this is really possible, but I'm trying my best. If
I don't think this is particularly quirky, but in an attempt to control my
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know why this is happening, but after submitting a form via JS (using
Don't be to hard on me, this is my first try with JSF. I
Don't ask why, but is there any way to suppress a failed linking error?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.