
March 3rd, 2013, 09:19 AM
|
 |
Contributing User
|
|
|
|
I modified a typical example I had ...
Code:
''' pg_exit1.py
exploring best ways to exit a Pygame loop
for key codes see:
http://www.pygame.org/docs/ref/key.html
'''
import pygame as pg
pg.init()
# create a 300 x 300 pixel display window
# the default background is black
win = pg.display.set_mode((300, 300))
# optional title bar caption
pg.display.set_caption('A Pygame Circle')
# draw a white circle
white = (255, 255, 255)
center = (150, 150)
radius = 100
# width of 0 (default) fills the circle
# otherwise it is thickness of outline
width = 0
# draw.circle(Surface, color, pos, radius, width)
# width of 0 (default) fills the circle
pg.draw.circle(win, white, center, radius, width)
# update the display window to show the drawing
pg.display.flip()
# event loop and exit conditions using
# specified key or display window x click
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
# most reliable exit on x click
pg.quit()
raise SystemExit
elif event.type == pg.KEYDOWN:
# optional exit with "a" key
if event.key == pg.K_a:
pg.quit()
raise SystemExit
|