PyGame is a Free and Open Source Python programming library for making multimedia application like games.
PyGame is highly portable and runs on nearly every platform and operating system. Millions of people have downloaded pygame itself, which is a whole lot of bits flying across the webs.
PIP is a package manager for Python packages, or modules if you like.
If you have Python version 3.4 or later, PIP is included by default.
You may need update your pip
version,
Run below command in command line:
python.exe -m pip install --upgrade pip
or
py -m pip install --upgrade pip
Note
The package is installed to particular version of python you are using.
Make sure you which version of python you are using:
py -V
-
Use the Command to install PyGame
py -m pip install -U pygame --user
-
Test if you pygame is installed
py -m pygame.examples.aliens
-
Try some other pyGame examples
py -m pygame.examples.stars
py -m pygame.examples.liquid
py -m pygame.examples.chimp
-
PyGame example source code:
could find in github pygame/examples/aliens.py
# ShowDot.py
# this script is show how to initial a pygame and draw a circle on tha page
import pygame
# initial the game
pygame.init()
screen = pygame.display.set_mode([800, 600])
# boolean flag to use control game run or quit
keep_going = True
# some data defined for game to use
GREEN = (0, 255, 0) # RGB color triplet for GREEN
radius = 50
# only when keep_going is true, the game will running
while keep_going:
# bellow code is for quit the game
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
# below code is for draw a circle in the screen
pygame.draw.circle(screen, GREEN, (100, 100), radius)
# refresh the screen displa
pygame.display.update()
pygame.quit()