]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151888: Add tkinter PhotoImage.redither method (GH-151889)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 22 Jun 2026 15:19:56 +0000 (18:19 +0300)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2026 15:19:56 +0000 (15:19 +0000)
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 <noreply@anthropic.com>
Doc/library/tkinter.rst
Doc/whatsnew/3.16.rst
Lib/test/test_tkinter/test_images.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2026-06-22-01-57-55.gh-issue-151888.hO7mxi.rst [new file with mode: 0644]

index 95b4a088ef9114e067a831fca10ab7002640d3fa..db6834fbea53e4e060e95c3aa2130fd1ac6c31dc 100644 (file)
@@ -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*.
index 1dc6a62cc16d2de06da96c5c2e99a7e8a794e657..eb13c67ac6a5e852a28f0efed9d054176c239e05 100644 (file)
@@ -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
 ---
 
index f9b314da9e8a915353b5db95a2f453d1a3d61f8f..099996feb5654a3f2dac5749538dcccc90d5dce6 100644 (file)
@@ -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()
index 7fcc7d764da317c4605a99cda6324c7d60e2a3d4..bf1a0290088fd215489444b8626a38b6ef8a5ab2 100644 (file)
@@ -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 (file)
index 0000000..8a2d5ed
--- /dev/null
@@ -0,0 +1,2 @@
+Add the :meth:`!tkinter.PhotoImage.redither` method, wrapping the photo image
+``redither`` Tk command.