'Pygame: AttributeError: 'pygame.Surface' object has no attribute 'display'
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?
Solution 1:[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')
Solution 2:[2]
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 :^
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Moosa Saadat |
Solution 2 | duo lapping - nice to meet you |