O'Reilly logo

Python Multimedia Beginner's Guide by Ninad Sathaye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - a simple application using PyGame

This example will make use of the modules we just discussed. For this application to work, you will need to install PyGame. The binary and source distribution of PyGame is available on Pygame's website.

  1. Create a new Python source file and write the following code in it.
    1 import pygame 2 import sys 3 4 pygame.init() 5 bgcolor = (200, 200, 100) 6 surf = pygame.display.set_mode((400,400)) 7 8 circle_color = (0, 255, 255) 9 x, y = 200, 300 10 circle_rad = 50 11 12 pygame.display.set_caption("My Pygame Window") 13 14 while True: 15 for event in pygame.event.get(): 16 if event.type == pygame.QUIT: 17 sys.exit() 18 elif event.type == pygame.KEYDOWN: 19 if event.key == pygame.K_UP: 20 y -= 10 21 elif ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required