From 50866e9ed3e4e0ebb60c20c3483a8df424c02722 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 5 Apr 2019 04:17:13 -0600 Subject: bpo-25451: Add transparency methods to tkinter.PhotoImage. (GH-10406) --- Lib/tkinter/__init__.py | 9 +++++++++ Lib/tkinter/test/test_tkinter/test_images.py | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'Lib/tkinter') diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index ae493ed3aa..57d5b25728 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -4124,6 +4124,15 @@ class PhotoImage(Image): args = args + ('-from',) + tuple(from_coords) self.tk.call(args) + def transparency_get(self, x, y): + """Return True if the pixel at x,y is transparent.""" + return self.tk.getboolean(self.tk.call( + self.name, 'transparency', 'get', x, y)) + + def transparency_set(self, x, y, boolean): + """Set the transparency of the pixel at x,y.""" + self.tk.call(self.name, 'transparency', 'set', x, y, boolean) + class BitmapImage(Image): """Widget which can display images in XBM format.""" diff --git a/Lib/tkinter/test/test_tkinter/test_images.py b/Lib/tkinter/test/test_tkinter/test_images.py index 85a8cd0495..2805d35a1f 100644 --- a/Lib/tkinter/test/test_tkinter/test_images.py +++ b/Lib/tkinter/test/test_tkinter/test_images.py @@ -320,6 +320,15 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase): self.assertEqual(image3.get(0, 0), image.get(4, 6)) self.assertEqual(image3.get(1, 2), image.get(5, 8)) + def test_transparency(self): + image = self.create() + self.assertEqual(image.transparency_get(0, 0), True) + self.assertEqual(image.transparency_get(4, 6), False) + image.transparency_set(4, 6, True) + self.assertEqual(image.transparency_get(4, 6), True) + image.transparency_set(4, 6, False) + self.assertEqual(image.transparency_get(4, 6), False) + tests_gui = (MiscTest, BitmapImageTest, PhotoImageTest,) -- cgit v1.2.1