Currently, I have downloaded python 2.7 and Pygame version 1.9.1 that is associated with 2.7. I ran the 'print pygame.ver' and I know that pygame has downloaded properly, however, when I wrote two different codes, I noticed two problems. One, when I close the Pygame window, it freezes and crashes. This isn't a smooth closing of the program. Second, There is one code that I typed, and when I executed it, a pygame window appears and is only black. Then it freezes, stops responding, and crashes without executing what the code says it is supposed to do.
CAN SOMEONE PLEASE HELP ME. Is there a problem with my code or the pygame program or compatibility or what? Please help.
Here is the code for the one that appears with a black window and crashes:
- Code: Select all
bif = 'bg.jpg'
mif = 'ball.png'
import pygame, sys
from pygame.locals import *
screen = pygame.display.set_mode((640, 360), 0, 32)
background = pygame.image.load(bif) .convert()
mouse_c = pygame.image.load(mif),convert_alpha()
for event in pygame.even.get():
if event.type == QUIT:
screen.blit (background, (0,0))
x, y = pygame.mouse.get_pos()
x -= mouse_c.get_width()/2
y -= mouse_c.get_height()/2
screen.blit (mouse_c, (x,y))