Error in My Code

I can’t seem to find the error in my code. It shows me this…

My code:

# and try to get to the end of the level.

import pygame
import random


# Colors
white = (255, 255, 255)
red = (255, 0, 0)
black = (0, 0, 0)

# Creating window
screen_width = 900
screen_height = 600
gameWindow = pygame.display.set_mode((screen_width, screen_height))

# Game Title
clock = pygame.time.Clock()
font = pygame.font.SysFont(None, 55)

def text_screen(text, color, x, y):
    screen_text = font.render(text, True, color)
    gameWindow.blit(screen_text, [x,y])

def plot_snake(gameWindow, color, snk_list, snake_size):
    for x,y in snk_list:
        pygame.draw.rect(gameWindow, color, [x, y, snake_size, snake_size])

def welcome():
    exit_game = False
    while not exit_game:
        text_screen("Welcome to Snakes", black, 260, 250)
        text_screen("Press Space Bar To Play", black, 232, 290)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit_game = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:


# Game Loop
def gameloop():
    # Game specific variables
    exit_game = False
    game_over = False
    snake_x = 45
    snake_y = 55
    velocity_x = 0
    velocity_y = 0
    snk_list = []
    snk_length = 1
    # Check if hiscore file exists
    if(not os.path.exists("hiscore.txt")):
        with open("hiscore.txt", "w") as f:

    with open("hiscore.txt", "r") as f:
        hiscore =

    food_x = random.randint(20, screen_width / 2)
    food_y = random.randint(20, screen_height / 2)
    score = 0
    init_velocity = 5
    snake_size = 30
    fps = 60
    while not exit_game:
        if game_over:
            with open("hiscore.txt", "w") as f:
            text_screen("Game Over! Press Enter To Continue", red, 100, 250)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    exit_game = True

Hey @EddyLostTeddy!

I can’t find why it doesn’t let you create a screen display, but If you use the pygame template you can actually see a window! I recommend redoing or just organizing your code on the pygame template!

1 Like

What device are you using Replit on?

I’m using a Windows 11.

oh nevermind I use linux

is it saying there is no file in the directory is that what it means by video device

it was saying that it can’t find a way to display the content - because there aren’t any suitable libraries installed. The posted solution works because the pygame template has several necessary X11 libraries in the makeLibraryPath array in replit.nix


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.