0

When I make my arguments named in below code, I get the TypeError. If I make the same arguments without specifying the name the code works fine. Both codes are shown below. Code on the top works fine, the one at the bottom gives "TypeError: Argument must be rect style object". The only thing I added was left=, top=, width= and height=

def draw_cell(self, surface):
    if self.type == Cell.BODY:
        pygame.draw.rect(surface=surface, color=self.color,
                         rect=pygame.rect.Rect(1 + self.column * SnakeGame.CELL_SIZE_IN_PIXELS,
                                               1 + self.row * SnakeGame.CELL_SIZE_IN_PIXELS,
                                               SnakeGame.CELL_SIZE_IN_PIXELS - 1,
                                               SnakeGame.CELL_SIZE_IN_PIXELS - 1),
                         width=0, border_radius=0)

def draw_cell(self, surface):
    if self.type == Cell.BODY:
        pygame.draw.rect(surface=surface, color=self.color,
                         rect=pygame.rect.Rect(left=1 + self.column * SnakeGame.CELL_SIZE_IN_PIXELS,
                                               top=1 + self.row * SnakeGame.CELL_SIZE_IN_PIXELS,
                                               width=SnakeGame.CELL_SIZE_IN_PIXELS - 1,
                                               height=SnakeGame.CELL_SIZE_IN_PIXELS - 1),
                         width=0, border_radius=0)
Oliver Jane
  • 164
  • 1
  • 12
  • Welcome to Stack Overflow. Please try to create a [mre]. For example, does this happen if you just use the code to create the `pygame.rect.Rect`, without trying to draw anything? Does it happen if you use constant values for the arguments? It's also useful to try breaking down complex statements into simpler ones (so that you can get an error message that points at the specific part that is wrong), and to show [complete](https://meta.stackoverflow.com/questions/359146) error messages. – Karl Knechtel May 23 '22 at 21:30
  • try doing `print(pygame.rect.Rect(left=1 + self.column * SnakeGame.CELL_SIZE_IN_PIXELS, top=1 + self.row * SnakeGame.CELL_SIZE_IN_PIXELS, width=SnakeGame.CELL_SIZE_IN_PIXELS - 1, height=SnakeGame.CELL_SIZE_IN_PIXELS - 1))` to see what exactly you are getting – Jacob May 27 '22 at 12:51
  • It gives the same error if I try to print "TypeError: Argument must be rect style object". It fails to create Rect, that's why it is giving error in first place. – Khizar Rehman May 30 '22 at 18:24

0 Answers0