S
S
Span4ev2022-02-25 05:05:32
Python
Span4ev, 2022-02-25 05:05:32

What's wrong? blit function in pygame: 'Rects' object has no attribute?

Explain to the old fool what's wrong. My face is already on fire, I don’t understand what’s wrong?

AttributeError: 'Rects' object has no attribute 'model'

Well, I look and see no reason, because the principles are the same.

well he writes:

hero = pg.Surface((40, 50))
hero.fill('blue')
rect = hero.get_rect()
screen.blit(hero, rect)


and I write:

self.model = pg.Surface((40, 50))
self.model.fill('black')
self.rect = model.get_rect()
screen.blit(self.model, self.rect)


What is the difference that I have an error?

class Rects:
  def __init(self):

    self.screen 			= screen
    self.screen_rect 		= screen.get_rect()
    self.screen_bg_color   	= (123, 104, 238)

    self.model = pg.Surface((40, 50))
    self.model.fill('black')
    self.rect = model.get_rect()
    self.rect.bottom = screen_rect.bottom
    self.rect.centerx = screen_rect.centerx

  def update_screen(self, screen):
    screen.fill((123, 104, 238))
    screen.blit(self.model, self.rect)
    pg.display.update()

def start(): 
  pg.init()
  pg.display.set_caption("отчание")
  fpsClock = pg.time.Clock()
  screen = pg.display.set_mode((screen_width, screen_height))
  rects = Rects()
  
  while True:
    check_events()
    rects.update_screen(screen)
    fpsClock.tick(FPS)

start()


I'm already so desperate that I want to quit everything. You sit, stare for an hour and do not understand why it does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YariKartoshe4ka, 2022-02-25
@Span4ev

What is the new magic method In python, their names end with two more underscores
def __init(self):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question