Skip to content

Commit

Permalink
Deprecate ImageTk._show
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 1, 2025
1 parent d7d48df commit 2c63162
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Tests/test_imagetk.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ def test_bitmapimage() -> None:

with pytest.raises(ValueError):
ImageTk.BitmapImage()


def test_show_deprecated() -> None:
im = hopper()

with pytest.warns(DeprecationWarning):
try:
ImageTk._show(im, "test")
except tk.TclError:
pass

Check warning on line 124 in Tests/test_imagetk.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_imagetk.py#L123-L124

Added lines #L123 - L124 were not covered by tests
8 changes: 8 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ Image.Image.get_child_images()
method uses an image's file pointer, and so child images could only be retrieved from
an :py:class:`PIL.ImageFile.ImageFile` instance.

ImageTk._show()
^^^^^^^^^^^^^^^

.. deprecated:: 11.2.0

``ImageTk._show()`` has been deprecated, as it was an unused helper for
:py:meth:`.Image.Image.show`.

Removed features
----------------

Expand Down
8 changes: 8 additions & 0 deletions docs/releasenotes/11.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ Image.Image.get_child_images()
method uses an image's file pointer, and so child images could only be retrieved from
an :py:class:`PIL.ImageFile.ImageFile` instance.

ImageTk._show()
^^^^^^^^^^^^^^^

.. deprecated:: 11.2.0

``ImageTk._show()`` has been deprecated, as it was an unused helper for
:py:meth:`.Image.Image.show`.

API Changes
===========

Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from typing import TYPE_CHECKING, Any, cast

from . import Image, ImageFile
from ._deprecate import deprecate

if TYPE_CHECKING:
from ._typing import CapsuleType
Expand Down Expand Up @@ -266,8 +267,6 @@ def getimage(photo: PhotoImage) -> Image.Image:


def _show(image: Image.Image, title: str | None) -> None:
"""Helper for the Image.show method."""

class UI(tkinter.Label):
def __init__(self, master: tkinter.Toplevel, im: Image.Image) -> None:
self.image: BitmapImage | PhotoImage
Expand All @@ -281,6 +280,7 @@ def __init__(self, master: tkinter.Toplevel, im: Image.Image) -> None:
image = self.image
super().__init__(master, image=image, bg="black", bd=0)

deprecate("ImageTk._show", 13)
if not getattr(tkinter, "_default_root"):
msg = "tkinter not initialized"
raise OSError(msg)
Expand Down

0 comments on commit 2c63162

Please sign in to comment.