Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/tkinter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_tkinter/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add the :meth:`!tkinter.PhotoImage.redither` method, wrapping the photo image
``redither`` Tk command.
Loading