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
- import pygame, sys
- from pygame.locals import *
- pygame.init()
- DISPLAYSURF = pygame.display.set_mode((400, 300))
- pygame.display.set_caption('Hello World!')
- while True: # main game loop
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- pygame.display.update()
OutPut
Pygame Modules
pygame.BufferProxy | pygame.cdrom | pygame.Color |
---|---|---|
pygame.display | pygame.draw | pygame.cursors |
pygame.event | pygame.event | pygame.font |
pygame.image | pygame.key | pygame.freetype |
pygame.example | pygame.gfxdraw | pygame.joystick |
pygame.locals | pygame.mixer | pygame.mouse |
pygame.mixer.music | pygame.overlay | pygame.Rect |
pygame.Surface | pygame.time | pygame.tests |
pygame.transform | pygame.sprite | pygame.scrap |
Congratulations @zohaibtahir! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Congratulations @zohaibtahir! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!