Q:

Maze screen changing

I want to make the program work so that when the sprite reaches the exit of the maze (-15 & +780), the screen changes to the next maze in the array rooms[]. 
I have attempted to integrate a position checker using the pre-existing self.pos although this seems to not be working. I have also added the 4 maze's into an array named rooms 
import pygame

pos = (0,0)
class Player(pygame.sprite.Sprite):
    def __init__(self, image, pos, background):
        super().__init__()
        self.image = image
        self.pos = pygame.Vector2(pos)
        self.rect = self.image.get_rect(center=self.pos)
        self.background = background

    def update(self, events, dt):
        pressed = pygame.key.get_pressed()
        move = pygame.Vector2((0, 0))
        if pressed[pygame.K_w]: move += (0, -1)
        if pressed[pygame.K_a]: move += (-1, 0)
        if pressed[pygame.K_s]: move += (0, 1)
        if pressed[pygame.K_d]: move += (1, 0)
        #if move.length() > 0: move.normalise_ip()

        new_pos = self.pos + move*(dt/5)
        new_rect = self.rect.copy()
        new_rect.center = new_pos
        new_rect.clamp_ip(self.background.get_rect())
        new_pos = new_rect.center

        hit_box = self.background.subsurface(new_rect)
        for x in range(new_rect.width):
            for y in range(new_rect.height):
                if sum(hit_box.get_at((x, y))) < 500:
                    return

        self.pos = new_pos
        self.rect.center = self.pos
        global pos 
        pos = self.pos

# Scenes
def room1():
    background = (pygame.image.load('maze1.jpg'))
    background = pygame.transform.rotate(background, -90)
    background = pygame.transform.scale(background, (800,600))

def room2():
    background = (pygame.image.load('maze2.jpg'))
    background = pygame.transform.rotate(background, -90)
    background = pygame.transform.scale(background, (800,600))

def room3():
    background = (pygame.image.load('maze3.jpg'))
    background = pygame.transform.rotate(background, -90)
    background = pygame.transform.scale(background, (800,600))

def room4():
    background = (pygame.image.load('maze4.jpg'))
    background = pygame.transform.rotate(background, -90)
    background = pygame.transform.scale(background, (800,600))

def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen_rect = screen.get_rect()

    clock = pygame.time.Clock()
    sprites = pygame.sprite.Group()

    rooms = []

    room = room1()
    rooms.append(room)
    room = room2()
    rooms.append(room)
    room = room3()
    rooms.append(room)
    room = room4()
    rooms.append(room)
    current_room_no = 0
    current_room = rooms[current_room_no]

    dt = 0
    while True:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                return
        if pos < -15:
            if current_room_no == 0:
                current_room_no = 2
                current_room = rooms[current_room_no]
                pos = 790
            elif current_room_no == 2:
                current_room_no = 1
                current_room = rooms[current_room_no]
                pos = 790
            else:
                current_room_no = 0
                current_room = rooms[current_room_no]
                pos = 790

        if pos > 801:
            if current_room_no == 0:
                current_room_no = 1
                current_room = rooms[current_room_no]
                pos = 0
            elif current_room_no == 1:
                current_room_no = 2
                current_room = rooms[current_room_no]
                pos = 0
            else:
                current_room_no = 0
                current_room = rooms[current_room_no]
                pos = 0

        pimg = pygame.Surface((10, 10))
        pimg.fill((200, 20, 20))
        sprites.add(Player(pimg, (50, 50), background))
        sprites.update(events, dt)
        screen.fill(pygame.Color('grey'))
        screen.blit(background, (0, 0))
        sprites.draw(screen)
        pygame.display.flip()
        dt = clock.tick(60)

if __name__ == '__main__':
    main()

Im hoping someone could help me integrate the screen changing feature as currently the code outputs an error about pos not being a variable and/or pos being called after its needed, but as you can see i clearly call the pos variable at the head of the code as a global variable.
Images: 
https://imgur.com/a/AgN5uJa

A:

In order to use the pos, you need to specify global pos at the beginning of main. In general the usage of global variables is not a good practice, try to refactor your code to have the pos inside the function. I'm worried that you are trying to compare a tuple with an int. That will yield an error also.
I took the liberty of altering your code quite a bit.

I used the player.pos for position tracking for the player sprite
I initialized the player only once per room, because the player was being spawned multiple times when events occurred in the game
I removed the room functions as you were doing something like rooms.append(room()), you were basically appending the result of the room functions, which was basically None. I didn't quite get why you wanted to do that
loaded the background also once, doesn't make sense to recreate the background surface every repaint
changed the initial position of the player to match the entrance of the maze
detected player's exit position, can be tweaked

Full code:
import pygame

class Player(pygame.sprite.Sprite):
    def __init__(self, image, pos, background):
        super().__init__()
        self.image = image
        self.pos = pygame.Vector2(pos)
        self.rect = self.image.get_rect(center=self.pos)
        self.background = background

    def update(self, events, dt):
        pressed = pygame.key.get_pressed()
        move = pygame.Vector2((0, 0))
        if pressed[pygame.K_w]: move += (0, -1)
        if pressed[pygame.K_a]: move += (-1, 0)
        if pressed[pygame.K_s]: move += (0, 1)
        if pressed[pygame.K_d]: move += (1, 0)
        #if move.length() > 0: move.normalise_ip()

        new_pos = self.pos + move*(dt/5)
        new_rect = self.rect.copy()
        new_rect.center = new_pos
        new_rect.clamp_ip(self.background.get_rect())
        new_pos = new_rect.center

        hit_box = self.background.subsurface(new_rect)
        for x in range(new_rect.width):
            for y in range(new_rect.height):
                if sum(hit_box.get_at((x, y))) < 500:
                    return

        self.pos = new_pos
        self.rect.center = self.pos
        pos = self.pos

# Scenes
def load_background(filename):
    background = (pygame.image.load(filename))
    background = pygame.transform.rotate(background, -90)
    background = pygame.transform.scale(background, (800,600))
    return background

def load_player(background):
    pimg = pygame.Surface((10, 10))
    pimg.fill((200, 20, 20))
    return Player(pimg, (25, 325), background)

def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen_rect = screen.get_rect()

    clock = pygame.time.Clock()
    sprites = pygame.sprite.Group()

    mazes = [
        "maze1.jpg",
        "maze2.jpg",
        "maze3.jpg",
        "maze4.jpg",
    ]

    mazes_len = len(mazes)

    player = None
    initialized = False
    current_maze = None
    dt = 0

    while True:
        events = pygame.event.get()

        for e in events:
            if e.type == pygame.QUIT:
                return

        if not initialized:
            current_maze = 0
            background = load_background(mazes[current_maze])
            player = load_player(background)
            sprites.add(player)
            initialized = True

        player_x = player.pos[0]
        player_y = player.pos[1]

        if player_x >= 780 and 275 < player_y < 375:
            current_maze += 1

            # reset to first maze if all mazes were done
            if current_maze >= mazes_len:
                current_maze = 0

            background = load_background(mazes[current_maze])
            sprites.empty()
            player = load_player(background)
            sprites.add(player)

        sprites.update(events, dt)

        screen.fill(pygame.Color('grey'))
        screen.blit(background, (0, 0))

        sprites.draw(screen)
        pygame.display.flip()
        dt = clock.tick(60)

if __name__ == '__main__':
    main()

