Showing posts with label PyGame easy example. Show all posts
Showing posts with label PyGame easy example. Show all posts

Friday, February 22, 2019

PyGame Window Demo/Setup

Hi. It's been a while since I've posted. I've been doing some coding lately and figured I'd do a quick recap for myself and you on how to do a basic PyGame program window setup.

This tutorial assumes you have already install Python and PyGame onto your machine. This is one of the most basic PyGame programs you could make and all it does is get a window setup for further coding. The code is pretty easy to follow along. You basically just initiate PyGame and then setup your window properties. Then you use PyGame to draw the window to the screen.

The code is:

# Michael L. Kelley Jr.# 2/20/2019# Pygame Window Demo
# Include statementsimport sys
import pygame


def Run_Game():
# Initiate pygame    pygame.init()
# Initiate pygame window
windowSurface = pygame.display.set_mode((640, 480), 0, 32)pygame.display.set_caption('Window Title Goes Here')

# Keep the window visible until quit
GameRunning = True
while GameRunning:        
for event in pygame.event.get():            
if event.type == pygame.QUIT:                
GameRunning = False
pygame.display.flip()

Run_Game()