import math import pygame from pygame.locals import * window = pygame.display.set_mode((600, 600)) pygame.display.set_caption('Hello, pygame!') screen = pygame.Surface((600, 600)) f=open('11.txt','r') for s in f: b=s.split(',') b[1]=int(b[1]) b[2]=int(b[2]) b[3]=int(b[3]) b[4]=int(b[4]) class Rectangle: def __init__(self): self.poligon_color = (255, 0, 0) self.poligon_points = [(b[1],b[2]),(b[3],b[4]),(400,150)] self.poligon_width = 0 def rand(self): print(self.pygame.draw.polygon(screen, poligon_color, poligon_points, poligon_width)) done = True while done: for e in pygame.event.get(): if e.type == pygame.QUIT: done = False screen.fill((50,50,50)) c=Rectangle() c.rand() window.blit(screen, (0,0)) pygame.display.flip()
выдает вот такую ошибку
Traceback (most recent call last):
File “C:\Users\1\Desktop\pp\111111.py”, line 36, in <module>
c.rand()
File “C:\Users\1\Desktop\pp\111111.py”, line 22, in rand
print(self.pygame.draw.polygon(screen, poligon_color, poligon_points, poligon_width))
AttributeError: Rectangle instance has no attribute ‘pygame’
В задаче нужно создать класс треугольник который берет размеры из файла