Pygame tutorial n. 1

Let’s start a serie of tutorial about Pygame. Ready? Go!

In this first part we will show:

  • how to create a window
  • how to create the main screen surface
  • ho to display a square surface on the screen

The code of Pygame tutorial 1 – window and surfaces

import pygame


pygame.init()

screen = pygame.display.set_mode((400, 600))
square = pygame.Surface((20, 20))
square.fill((255, 0, 0))
while True:
    screen.blit(square, (100, 100))
    if pygame.event.get(pygame.QUIT):
        break
    pygame.display.update()

pygame.quit()


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.