Pygame: AttributeError: объект 'pygame.Surface' не имеет атрибута 'display'

Код:

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

Когда я запускаю программу, она выдает следующую ошибку:

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'

В чем проблема? Как это решить?


person Aravinth Unique Star    schedule 04.04.2020    source источник


Ответы (1)


Проблема в линии. Вы можете удалить его, и ваш код будет запущен.

screen.display.set_caption("Snake")

Пояснение:

В pygame есть разница между Surface и display. Вы можете установить заголовок для display, который вы делаете в этой строке:

pygame.display.set_caption('Slither.eat - The Snake Game')
person Moosa Saadat    schedule 04.04.2020