From 9ec0b580059de7b7082e323412f09422d04ede62 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 22 Jun 2026 01:58:32 +0300 Subject: [PATCH] gh-151888: Add tkinter PhotoImage.redither method Wrap the photo image "redither" Tk command (since Tk 8.5) as the method PhotoImage.redither(), which recalculates the dithered image in each window where it is displayed (useful when the image data was supplied in pieces), completing the wrapping of the photo image subcommands. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01XWevzas4XVpjzedzR9gKVo --- Doc/library/tkinter.rst | 8 ++++++++ Doc/whatsnew/3.16.rst | 4 ++++ Lib/test/test_tkinter/test_images.py | 6 ++++++ Lib/tkinter/__init__.py | 7 +++++++ .../2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst | 2 ++ 5 files changed, 27 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index 222a4d0128bd8d..3e8475a09095fe 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -5860,6 +5860,14 @@ Image classes it is displayed as transparent and the background of whatever window it is displayed in shows through. + .. method:: redither() + + Recalculate the dithered image in each window where it is displayed. + This is useful when the image data was supplied in pieces, in which case + the dithered image may not be exactly correct. + + .. versionadded:: next + .. method:: cget(option) Return the current value of the configuration option *option*. diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index ec8e367d938ddb..ddd7b6d0fa221c 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -157,6 +157,10 @@ tkinter synchronization of the displayed view with the underlying text. (Contributed by Serhiy Storchaka in :gh:`151675`.) +* Added the :meth:`~tkinter.PhotoImage.redither` method which recalculates the + dithered image when its data was supplied in pieces. + (Contributed by Serhiy Storchaka in :gh:`151888`.) + xml --- diff --git a/Lib/test/test_tkinter/test_images.py b/Lib/test/test_tkinter/test_images.py index f9b314da9e8a91..099996feb5654a 100644 --- a/Lib/test/test_tkinter/test_images.py +++ b/Lib/test/test_tkinter/test_images.py @@ -311,6 +311,12 @@ def test_blank(self): self.assertEqual(image.height(), 16) self.assertEqual(image.get(4, 6), self.colorlist(0, 0, 0)) + def test_redither(self): + image = self.create() + pixel = image.get(4, 6) + image.redither() # Recalculates the dithering; the data is unchanged. + self.assertEqual(image.get(4, 6), pixel) + def test_copy(self): image = self.create() image2 = image.copy() diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 8bdf7cc1e2d96b..10360df473331c 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -4469,6 +4469,13 @@ def blank(self): """Display a transparent image.""" self.tk.call(self.name, 'blank') + def redither(self): + """Recalculate the dithered image in each window where it is displayed. + + Useful when the image data was supplied in pieces, in which case the + dithered image may not be exactly correct.""" + self.tk.call(self.name, 'redither') + def cget(self, option): """Return the value of OPTION.""" return self.tk.call(self.name, 'cget', '-' + option) diff --git a/Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst b/Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst new file mode 100644 index 00000000000000..8a2d5ed765d234 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst @@ -0,0 +1,2 @@ +Add the :meth:`!tkinter.PhotoImage.redither` method, wrapping the photo image +``redither`` Tk command.