The following works with both under python 3.4.0, etc, as above, though the SDL2 version is slow.
import sys
import pygame
# or import pygame_sdl2 as pygame
pygame.init()
window_size = width, height = (800, 600)
speed = [5, 5]
background = "" 144, 0) #colour. red, green and blue.
screen = pygame.display.set_mode(window_size)
ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()
keep_going = True
try: #get ready to deal with any problems
 while keep_going:
ÂÂÂ for event in pygame.event.get():
ÂÂÂÂÂ if event.type == pygame.QUIT:
ÂÂÂÂÂÂÂ keep_going = False #exit the loop
ÂÂÂ ballrect = ballrect.move(speed)
ÂÂÂ if ballrect.left < 0 or ballrect.right > width:
ÂÂÂÂÂ speed[0] = -speed[0]
ÂÂÂ if ballrect.top < 0 or ballrect.bottom > height:
ÂÂÂÂÂ speed[1] = -speed[1]
ÂÂÂ screen.fill(background)
ÂÂÂ screen.blit(ball, ballrect)
ÂÂÂ pygame.display.flip()
except:
 raise #show what went wrong
finally:
 pygame.display.quit() #close the window