Method: Move the background images down at (0, 0) and (0, -img.heigh), and when one of them is at (0, img.heigth), place it again at (0, -img.heigh).

Specific code:

import pygame
import sys
import pygame.sprite as sprite

theClock = pygame.time.Clock()

# load image
background = pygame.image.load('background.gif')

background_size = background.get_size()
background_rect = background.get_rect()
screen = pygame.display.set_mode(background_size)
w,h = background_size

# Background 1 initial position
x, y = 0.0
# Background 2 initial position
x1, y1 = 0, -h

running = True

while running:
    screen.blit(background,background_rect)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    Constantly update position and implement background scrolling
    y1 += 5
    y += 5
    screen.blit(background,(x,y))
    screen.blit(background,(x1,y1))
    if y > h:
        y = -h
    if y1 > h:
        y1 = -h
    
    pygame.display.flip()
    pygame.display.update()
    theClock.tick(10)
Copy the code