https://github.com/python/cpython/commit/b86c305c746f6d5be52227c946b77a009bad8928 commit: b86c305c746f6d5be52227c946b77a009bad8928 branch: main author: Serhiy Storchaka <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-06-22T15:19:56Z summary:
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 <[email protected]> files: A Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst M Doc/library/tkinter.rst M Doc/whatsnew/3.16.rst M Lib/test/test_tkinter/test_images.py M Lib/tkinter/__init__.py diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index 95b4a088ef9114..db6834fbea53e4 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 1dc6a62cc16d2d..eb13c67ac6a5e8 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 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 7fcc7d764da317..bf1a0290088fd2 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -4571,6 +4571,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. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
