Skip to content

Commit 6211d30

Browse files
authored
Merge pull request #497 from JaskRendix/patch-1
Replace deprecated `pygame.image.fromstring` with `pygame.image.frombytes`
2 parents 156d1b6 + a769a34 commit 6211d30

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pygame_menu/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,12 @@ def load_pygame_image_file(image_path: str, **kwargs) -> 'pygame.Surface':
403403
pil_invalid_exception = UnidentifiedImageError
404404
img_pil = Image.open(image_path)
405405
# noinspection PyTypeChecker,PyUnusedLocal
406-
surface = pygame.image.fromstring(
407-
img_pil.tobytes(), img_pil.size, img_pil.mode).convert()
406+
if pygame.version.vernum >= (2, 3, 0):
407+
surface = pygame.image.frombytes(
408+
img_pil.tobytes(), img_pil.size, img_pil.mode).convert()
409+
else:
410+
surface = pygame.image.fromstring(
411+
img_pil.tobytes(), img_pil.size, img_pil.mode).convert()
408412
except (ModuleNotFoundError, ImportError):
409413
warn(f'Image file "{image_path}" could not be loaded, as pygame.error '
410414
f'is raised. To avoid this issue install the Pillow library')

0 commit comments

Comments
 (0)