Pygpoint 2: adjust the screen to the images size

Previous codeNEXT

Pygame + Powerpoint = Pygpoint.

This new version fits the screen to images, making the code more “general use”

# load a spreadsheet
import pygame
import sys
from glob import glob

def init():
    "Load images and set the screen to fit them"
    global images
    global screen
    global clock

    images = [pygame.image.load(png) for png in glob("images01\\*.png")]
    width = images[0].get_rect().width
    height = images[0].get_rect().height
    screen = pygame.display.set_mode((width, height))
    clock = pygame.time.Clock()




init()
counter = 0
loop = 1
while loop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = 0
        if event.type == pygame.KEYDOWN:
            if counter < 7:
                counter += 1
            else:
                counter = 0
    screen.fill((0,0,0))
    screen.blit(images[counter], (0, 0))
    pygame.display.flip()
    clock.tick(10)

pygame.quit()
sys.exit()

Part 1


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.