Python gaming with pygame

Pygame is the future of gaming with the python.

Pygame provides the Graphical User Interface

GUI vs. CLI

The Python programs that you can write with Python’s built-in functions only deal with text through the print() and input() functions. Your program can display text on the screen and let the user type in text from the keyboard. This type of program has a command line interface, or CLI (which is pronounced like the first part of ―climb‖ and rhymes with ―sky‖). These programs are somewhat limited because they can’t display graphics, have colors, or use the mouse. These CLI programs only get input from the keyboard with the input() function and even then the user must press Enter before the program can respond to the input. This means real-time (that is, continuing to run code without waiting for the user) action games are impossible to make.
Pygame provides functions for creating programs with a graphical user interface, or GUI (pronounced, ―gooey‖). Instead of a text-based CLI, programs with a graphics-based GUI can show a window with images and colors.


The simple Hello world with Pygame

  1. import pygame, sys
  2. from pygame.locals import *
  3. pygame.init()
  4. DISPLAYSURF = pygame.display.set_mode((400, 300))
  5. pygame.display.set_caption('Hello World!')
  6. while True: # main game loop
  7. for event in pygame.event.get():
  8. if event.type == QUIT:
  9. pygame.quit()
  10. sys.exit()
  11. pygame.display.update()

OutPut

Capture.PNG

Pygame Modules


pygame.BufferProxypygame.cdrompygame.Color
pygame.displaypygame.drawpygame.cursors
pygame.eventpygame.eventpygame.font
pygame.imagepygame.keypygame.freetype
pygame.examplepygame.gfxdrawpygame.joystick
pygame.localspygame.mixerpygame.mouse
pygame.mixer.musicpygame.overlaypygame.Rect
pygame.Surfacepygame.timepygame.tests
pygame.transformpygame.spritepygame.scrap

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center