Python pygame=2.1.3.dev8 is broken. Not drawing dimensions of pygame.draw of any shape

Question:

I currently have pygame version 2.1.3.dev8 as I am running python 3.11 and pygame currently does not support that version of python. So following solutions I found online, the best solution was when I ran pip3 install pygame --pre which gave me the current version of pygame above. So far, everything of pygame works, but drawing any shape does not.

Using the following code, I am able to temporary create a window, attempt to draw a rectangle, print the rectangle information (AKA it’s x, y, width and height).

import pygame

pygame.init()
screen = pygame.display.set_mode((600, 600))
pygame.display.set_caption('Title')
tpm = pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(700, 1000, 64, 64), 0)
print(tpm)
pygame.quit()

The output I get is <rect(700, 1000, 0, 0)> showing that the x and y is fine. But the dimensions for width and height shows as 0. This is the same outcome for any pygame draw functionality.

Note: As far as I know, I can’t install any other versions of pygame. When I do, I get setup error:

 error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [77 lines of output]
Asked By: Anthony Massaad

||

Answers:

No this is the desired behavior. See pygame.draw.rect:

Returns
a rect bounding the changed pixels, if nothing is drawn the bounding rect’s position will be the position of the given rect parameter and its width and height will be 0

Since your rectangle is outside the boundaries of the target surface, the width and height of the returned rectangle are 0. You must draw the rectangle inside the boundaries of the window. e.g.:

tpm = pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(700, 1000, 64, 64), 0)

tpm = pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(100, 100, 64, 64), 0)
Answered By: Rabbid76
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.