0

Code:

import pygame, sys, os 
from pygame.locals import *
red = (255,0,0)
pygame.init()
window = pygame.display.set_mode((1000,600))
pygame.display.set_caption('Slither.eat - The Snake Game')
screen = pygame.display.get_surface()
screen.fill(red)
screen.display.set_caption("Snake")
pygame.display.flip()
while True:
    print("Slither.eat - The Snake Game!")
    pass

When I execute the program, it gives the following error:

File "C:\Users\ELCOT\Python38\pygame-master\pygame-master\001 PyGame Hello World.py", line 13, in <module>
    screen.display.set_caption("Snake")
AttributeError: 'pygame.Surface' object has no attribute 'display'

What is the problem? How to solve it?

0xdb
  • 3,539
  • 1
  • 21
  • 37

2 Answers2

1

The problem is with the line. You can remove it and your code will run.

screen.display.set_caption("Snake")

Explanation:

There's a difference between Surface and display in pygame. You can set a caption for a display which you are doing in this line:

pygame.display.set_caption('Slither.eat - The Snake Game')
Moosa Saadat
  • 1,159
  • 1
  • 8
  • 20
0

which title do you want? 'Slither.eat - The Snake Game' or Snake if you want Slither.eat - The Snake Game then type in:

pygame.display.set_caption('Slither.eat - The Snake Game')

however, if you want the snake game as title type in:

pygame.display.set_caption(The Snake Game)

hope it helps, even though its been 2 years :^