From: Serhiy Storchaka Date: Mon, 22 Jun 2026 15:19:56 +0000 (+0300) Subject: gh-151888: Add tkinter PhotoImage.redither method (GH-151889) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b86c305c746f6d5be52227c946b77a009bad8928;p=thirdparty%2FPython%2Fcpython.git gh-151888: Add tkinter PhotoImage.redither method (GH-151889) 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 --- diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index 95b4a088ef91..db6834fbea53 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -6076,6 +6076,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 1dc6a62cc16d..eb13c67ac6a5 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -194,6 +194,11 @@ tkinter badge) and :meth:`~tkinter.Wm.wm_stackorder` (toplevel stacking order). (Contributed by Serhiy Storchaka in :gh:`151874`.) +* 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 f9b314da9e8a..099996feb565 100644 --- a/Lib/test/test_tkinter/test_images.py +++ b/Lib/test/test_tkinter/test_images.py @@ -311,6 +311,12 @@ class PhotoImageTest(BaseImageTest, AbstractTkTest, unittest.TestCase): 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 7fcc7d764da3..bf1a0290088f 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -4571,6 +4571,13 @@ class PhotoImage(Image): """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 000000000000..8a2d5ed765d2 --- /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.