I planned to write code in Pygame, and I was just starting out with the basics and found that the executable code was very slow. When I press a key, it takes some time to print it in the terminal (there is no picture for it).
I am running Python 2.6, after having run into this problem, I refused. Upon further testing, I found that the whole system was slowing down . Has anyone come across this or got a solution so that it works faster and / or prevents the system from slowing down?
OS - Ubuntu Hardware - Macbook Pro
import pygame
import pygame.locals
pygame.mixer.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("bla")
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(pygame.Color("green"))
screen.blit(background, (0, 0))
looping = True
while looping:
for event in pygame.event.get():
if event.type == pygame.QUIT:
looping = False
elif event.type == pygame.KEYDOWN:
keyName = pygame.key.name(event.key)
print "key pressed:", keyName
if event.key == pygame.K_SPACE:
print "Loading Music"
pygame.mixer.music.load("born.mp3")
elif event.key == pygame.K_ESCAPE:
looping = False
pygame.display.flip()
If there is additional information that I can provide, I would be happy to help.
source
share