Skip to content

Commit 9ec0b58

Browse files
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XWevzas4XVpjzedzR9gKVo
1 parent f28ef85 commit 9ec0b58

5 files changed

Lines changed: 27 additions & 0 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,6 +5860,14 @@ Image classes
58605860
it is displayed as transparent and the background of whatever window it
58615861
is displayed in shows through.
58625862

5863+
.. method:: redither()
5864+
5865+
Recalculate the dithered image in each window where it is displayed.
5866+
This is useful when the image data was supplied in pieces, in which case
5867+
the dithered image may not be exactly correct.
5868+
5869+
.. versionadded:: next
5870+
58635871
.. method:: cget(option)
58645872

58655873
Return the current value of the configuration option *option*.

Doc/whatsnew/3.16.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ tkinter
157157
synchronization of the displayed view with the underlying text.
158158
(Contributed by Serhiy Storchaka in :gh:`151675`.)
159159

160+
* Added the :meth:`~tkinter.PhotoImage.redither` method which recalculates the
161+
dithered image when its data was supplied in pieces.
162+
(Contributed by Serhiy Storchaka in :gh:`151888`.)
163+
160164
xml
161165
---
162166

Lib/test/test_tkinter/test_images.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ def test_blank(self):
311311
self.assertEqual(image.height(), 16)
312312
self.assertEqual(image.get(4, 6), self.colorlist(0, 0, 0))
313313

314+
def test_redither(self):
315+
image = self.create()
316+
pixel = image.get(4, 6)
317+
image.redither() # Recalculates the dithering; the data is unchanged.
318+
self.assertEqual(image.get(4, 6), pixel)
319+
314320
def test_copy(self):
315321
image = self.create()
316322
image2 = image.copy()

Lib/tkinter/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,6 +4469,13 @@ def blank(self):
44694469
"""Display a transparent image."""
44704470
self.tk.call(self.name, 'blank')
44714471

4472+
def redither(self):
4473+
"""Recalculate the dithered image in each window where it is displayed.
4474+
4475+
Useful when the image data was supplied in pieces, in which case the
4476+
dithered image may not be exactly correct."""
4477+
self.tk.call(self.name, 'redither')
4478+
44724479
def cget(self, option):
44734480
"""Return the value of OPTION."""
44744481
return self.tk.call(self.name, 'cget', '-' + option)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the :meth:`!tkinter.PhotoImage.redither` method, wrapping the photo image
2+
``redither`` Tk command.

0 commit comments

Comments
 (0)