Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading