이 질문은 많이 묻지 만, 불행히도 내 문제에 맞는 답을 찾지 못했습니다. 파이썬을 배우려는 초보자이기 때문에 가능한 한 일반적인 대답을 선호합니다. 미리 감사드립니다. 그것에 원으로, 게임을위한 창을 만드는 데 사용됩니다Python - AttributeError : 'Particle'객체에 'display'속성이 없습니다.
import pygame
background_colour = (255, 255, 255)
(width, height) = (300, 200)
class Particle:
def __init__(self, x, y, size):
self.x = x
self.y = y
self.size = size
self.colour = (0, 0, 255)
self.thickness = 1
screen = pygame.display.set_mode((width, height))
def display(self):
pygame.draw.circle(screen, self.colour, (self.x, self.y), self.size, self.thickness)
pygame.display.set_caption('Agar')
screen.fill(background_colour)
pygame.display.flip()
running = True
my_first_particle = Particle(150, 50, 15)
my_first_particle.display()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
:
이
내가 파이 게임 라이브러리를 사용하여 파이썬의 기초에 대한 자습서를 수행하여 얻은 코드입니다. 원은 나중에 비슷한 방식으로 여러 번 사용되는 클래스로 정의됩니다.Traceback (most recent call last):
File "C:/Users/20172542/PycharmProjects/agarTryout/Agar.py", line 29, in <module>
my_first_particle.display()
AttributeError: 'Particle' object has no attribute 'display'
어떻게 원리를 이해하고 있지 않다,이 오류에 대한 구체적인 해결책은 무엇인가 :
나는 다음과 같은 오류가있어?시간과 노력에 감사드립니다.
'Particle' 클래스는'display' 메소드를 정의하지 않습니다. 다른 것을'display '라고 부르는 것을 의미 했습니까? 아마도'파이 게임 '일까요? – FamousJameous
정확히 무엇을 요구하고 있는지 잘 모름 - 오류가 명확합니다. 존재하지 않는 방법을 부르고 있습니다. – jhpratt