From 324b39fb78d05bde8efd93abb252393c29e3d611 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Mon, 23 Apr 2018 13:45:27 -0400 Subject: [PATCH 01/13] bpo-33289: Return RGB triplet of ints from tkinter.colorchooser --- Lib/tkinter/__init__.py | 12 +++- Lib/tkinter/colorchooser.py | 60 +++++++++++-------- Lib/tkinter/test/test_tkinter/test_misc.py | 18 ++++++ .../2018-04-23-13-44-10.bpo-33289.anBnUr.rst | 2 + 4 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-04-23-13-44-10.bpo-33289.anBnUr.rst diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index a3378d012fb41a..40697e6b3438ff 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1152,8 +1152,16 @@ def winfo_reqwidth(self): self.tk.call('winfo', 'reqwidth', self._w)) def winfo_rgb(self, color): - """Return tuple of decimal values for red, green, blue for - COLOR in this widget.""" + """Return a tuple of the RGB values for color in this widget. + + Args: + color: String representation of the color either as a name + or as # followed by 4-, 8-, 12-, or 16-bit hex values. + + Returns: + A 3-tuple of ints in the range (0, 65535) of the red, green, + and blue intensities for color. + """ return self._getints( self.tk.call('winfo', 'rgb', self._w, color)) diff --git a/Lib/tkinter/colorchooser.py b/Lib/tkinter/colorchooser.py index 3cfc06f6f1fae6..8f3b8832e0da0e 100644 --- a/Lib/tkinter/colorchooser.py +++ b/Lib/tkinter/colorchooser.py @@ -8,57 +8,69 @@ # fixed initialcolor handling in August 1998 # -# -# options (all have default values): -# -# - initialcolor: color to mark as selected when dialog is displayed -# (given as an RGB triplet or a Tk color string) -# -# - parent: which window to place the dialog on top of -# -# - title: dialog title -# from tkinter.commondialog import Dialog __all__ = ["Chooser", "askcolor"] -# -# color chooser class - class Chooser(Dialog): - "Ask for a color" + """Create a dialog for the tk_chooseColor command. + + Args: + master: The master widget for this dialog. If not provided, + defaults to options['parent'] (if defined). + options: Dictionary of options for the tk_chooseColor call. + initialcolor: Specifies the selected color when the + dialog is first displayed. This can be a tk color + string or a 3-tuple of ints in the range (0, 255) + for an RGB triplet. + parent: The parent window of the color dialog. The + color dialog is displayed on top of this. + title: A string for the title of the dialog box. + """ command = "tk_chooseColor" def _fixoptions(self): + """Ensure initialcolor is a tk color string. + + Convert initialcolor from a RGB triplet to a color string. + """ try: - # make sure initialcolor is a tk color string color = self.options["initialcolor"] if isinstance(color, tuple): - # assume an RGB triplet + # Assume an RGB triplet. self.options["initialcolor"] = "#%02x%02x%02x" % color except KeyError: pass def _fixresult(self, widget, result): - # result can be somethings: an empty tuple, an empty string or - # a Tcl_Obj, so this somewhat weird check handles that + """Adjust result returned from call to tk_chooseColor. + + Return both an RGB tuple of ints in the range (0, 255) and the + tk color string in the form #xxxxxx. + """ + # Result can be many things: an empty tuple, an empty string, or + # a Tcl_Obj, so this somewhat weird check handles that. if not result or not str(result): - return None, None # canceled + return None, None # canceled - # to simplify application code, the color chooser returns - # an RGB tuple together with the Tk color string + # To simplify application code, the color chooser returns + # an RGB tuple together with the Tk color string. r, g, b = widget.winfo_rgb(result) - return (r/256, g/256, b/256), str(result) + return (r//256, g//256, b//256), str(result) # # convenience stuff -def askcolor(color = None, **options): - "Ask for a color" +def askcolor(color=None, **options): + """Display dialog window for selection of a color. + + Convenience wrapper for the Chooser class. Displays the color + chooser dialog with color as the initial value. + """ if color: options = options.copy() diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 1e089747a91ee5..242b433c68f3da 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -192,6 +192,24 @@ def test_clipboard_astral(self): with self.assertRaises(tkinter.TclError): root.clipboard_get() + def test_winfo_rgb(self): + root = self.root + rgb = root.winfo_rgb + + # Color name. + self.assertEqual(rgb('red'), (65535, 0, 0)) + # #RGB + self.assertEqual(rgb('#f00'), (65535, 0, 0)) + # #RRGGBB + self.assertEqual(rgb('#ff0000'), (65535, 0, 0)) + # #RRRGGGBBB + self.assertEqual(rgb('#000fff000'), (0, 65535, 0)) + # #RRRRGGGGBBBB + self.assertEqual(rgb('#ffff0000ffff'), (65535, 0, 65535)) + # RGB triplet is invalid input. + with self.assertRaises(tkinter.TclError): + rgb((255, 0, 0)) + tests_gui = (MiscTest, ) diff --git a/Misc/NEWS.d/next/Library/2018-04-23-13-44-10.bpo-33289.anBnUr.rst b/Misc/NEWS.d/next/Library/2018-04-23-13-44-10.bpo-33289.anBnUr.rst new file mode 100644 index 00000000000000..52d9ac9dd902cd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-23-13-44-10.bpo-33289.anBnUr.rst @@ -0,0 +1,2 @@ +Correct call to :mod:`tkinter.colorchooser` to return RGB triplet of ints +instead of floats. Patch by Cheryl Sabella. From 179d3a2024ac9794c3333fe5e26f83aa4b45be01 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Mon, 23 Apr 2018 18:27:20 -0400 Subject: [PATCH 02/13] Clearer tests for winfo_rgb. --- Lib/tkinter/__init__.py | 11 +--------- Lib/tkinter/test/test_tkinter/test_misc.py | 25 +++++++++++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 40697e6b3438ff..01937687a56e51 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1152,16 +1152,7 @@ def winfo_reqwidth(self): self.tk.call('winfo', 'reqwidth', self._w)) def winfo_rgb(self, color): - """Return a tuple of the RGB values for color in this widget. - - Args: - color: String representation of the color either as a name - or as # followed by 4-, 8-, 12-, or 16-bit hex values. - - Returns: - A 3-tuple of ints in the range (0, 65535) of the red, green, - and blue intensities for color. - """ + """Return a tuple of the RGB values for color in this widget.""" return self._getints( self.tk.call('winfo', 'rgb', self._w, color)) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 242b433c68f3da..da485f74ded4ca 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -198,14 +198,23 @@ def test_winfo_rgb(self): # Color name. self.assertEqual(rgb('red'), (65535, 0, 0)) - # #RGB - self.assertEqual(rgb('#f00'), (65535, 0, 0)) - # #RRGGBB - self.assertEqual(rgb('#ff0000'), (65535, 0, 0)) - # #RRRGGGBBB - self.assertEqual(rgb('#000fff000'), (0, 65535, 0)) - # #RRRRGGGGBBBB - self.assertEqual(rgb('#ffff0000ffff'), (65535, 0, 65535)) + self.assertEqual(rgb('dark slate blue'), (18504, 15677, 35723)) + # #RGB - extends each 4-bit hex value to be 16-bit. + self.assertEqual(rgb('#f00'), + (int('ffff', 16), 0, 0)) + # #RRGGBB - extends each 8-bit hex value to be 16-bit. + self.assertTrue(rgb('#483d8b') == + (int('4848', 16), int('3d3d', 16), int('8b8b', 16)) == + (18504, 15677, 35723)) # dark slate blue + # #RRRGGGBBB - uses 2 highest order bits for each color. + self.assertEqual(rgb('#123456789'), + (int('1212', 16), int('4545', 16), int('7878', 16))) + # #RRRRGGGGBBBB - uses 2 highest order bits for each color. + self.assertEqual(rgb('#1234567800ff'), + (int('1212', 16), int('5656', 16), int('0000', 16))) + # Invalid string. + with self.assertRaises(tkinter.TclError): + rgb('#1234567890') # RGB triplet is invalid input. with self.assertRaises(tkinter.TclError): rgb((255, 0, 0)) From d936fe5ca6ae2cfd7d75950b8a35c111230e231a Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Wed, 16 May 2018 08:42:59 -0400 Subject: [PATCH 03/13] Add missing test_colorchooser source --- Lib/tkinter/colorchooser.py | 4 +- .../test/test_tkinter/test_colorchooser.py | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Lib/tkinter/test/test_tkinter/test_colorchooser.py diff --git a/Lib/tkinter/colorchooser.py b/Lib/tkinter/colorchooser.py index 8f3b8832e0da0e..e2fb69dba92763 100644 --- a/Lib/tkinter/colorchooser.py +++ b/Lib/tkinter/colorchooser.py @@ -49,10 +49,10 @@ def _fixresult(self, widget, result): """Adjust result returned from call to tk_chooseColor. Return both an RGB tuple of ints in the range (0, 255) and the - tk color string in the form #xxxxxx. + tk color string in the form #rrggbb. """ # Result can be many things: an empty tuple, an empty string, or - # a Tcl_Obj, so this somewhat weird check handles that. + # a _tkinter.Tcl_Obj, so this somewhat weird check handles that. if not result or not str(result): return None, None # canceled diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py new file mode 100644 index 00000000000000..54997bac1c8829 --- /dev/null +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -0,0 +1,42 @@ +import unittest +import tkinter +from tkinter import colorchooser +from test.support import requires, run_unittest, gc_collect +from tkinter.test.support import AbstractTkTest + +requires('gui') + +class ChooserTest(AbstractTkTest, unittest.TestCase): + + @classmethod + def setUpClass(cls): + AbstractTkTest.setUpClass.__func__(cls) + cls.cc = colorchooser.Chooser(initialcolor='red') + + def test_fixoptions(self): + cc = self.cc + cc._fixoptions() + self.assertEqual(cc.options['initialcolor'], 'red') + + cc.options['initialcolor'] = '#ffff00000000' + cc._fixoptions() + self.assertEqual(cc.options['initialcolor'], '#ffff00000000') + + cc.options['initialcolor'] = (255, 0, 0) + cc._fixoptions() + self.assertEqual(cc.options['initialcolor'], '#ff0000') + + def test_fixresult(self): + cc = self.cc + self.assertEqual(cc._fixresult(self.root, ()), (None, None)) + self.assertEqual(cc._fixresult(self.root, ''), (None, None)) + self.assertEqual(cc._fixresult(self.root, 'red'), + ((255, 0, 0), 'red')) + self.assertEqual(cc._fixresult(self.root, '#ff0000'), + ((255, 0, 0), '#ff0000')) + + +tests_gui = (ChooserTest, ) + +if __name__ == "__main__": + run_unittest(*tests_gui) From e0c9cec8e2a5f45644762ba6fd7dc7973deec677 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 9 Feb 2020 15:27:09 -0500 Subject: [PATCH 04/13] Use better examples in tests --- Lib/tkinter/test/test_tkinter/test_misc.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index da485f74ded4ca..45a65fa24ce140 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -200,24 +200,19 @@ def test_winfo_rgb(self): self.assertEqual(rgb('red'), (65535, 0, 0)) self.assertEqual(rgb('dark slate blue'), (18504, 15677, 35723)) # #RGB - extends each 4-bit hex value to be 16-bit. - self.assertEqual(rgb('#f00'), - (int('ffff', 16), 0, 0)) + self.assertEqual(rgb('#4CE'), (0x4444, 0xCCCC, 0xEEEE)) # #RRGGBB - extends each 8-bit hex value to be 16-bit. - self.assertTrue(rgb('#483d8b') == - (int('4848', 16), int('3d3d', 16), int('8b8b', 16)) == - (18504, 15677, 35723)) # dark slate blue + self.assertEqual(rgb('#483d8b'), (0x4848, 0x3d3d, 0x8b8b)) # #RRRGGGBBB - uses 2 highest order bits for each color. - self.assertEqual(rgb('#123456789'), - (int('1212', 16), int('4545', 16), int('7878', 16))) + self.assertEqual(rgb('#123456789'), (0x1212, 0x4545, 0x7878)) # #RRRRGGGGBBBB - uses 2 highest order bits for each color. - self.assertEqual(rgb('#1234567800ff'), - (int('1212', 16), int('5656', 16), int('0000', 16))) + self.assertEqual(rgb('#123456789abc'), (0x1212, 0x5656, 0x9a9a)) # Invalid string. with self.assertRaises(tkinter.TclError): - rgb('#1234567890') + rgb('#123456789a') # RGB triplet is invalid input. with self.assertRaises(tkinter.TclError): - rgb((255, 0, 0)) + rgb((111, 78, 55)) tests_gui = (MiscTest, ) From a740841183033fda1ed0178e39646e10e51ea343 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 9 Feb 2020 15:30:47 -0500 Subject: [PATCH 05/13] Remove gc_collect --- Lib/tkinter/test/test_tkinter/test_colorchooser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index 54997bac1c8829..2e49a9a6dcd0e5 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -1,7 +1,7 @@ import unittest import tkinter from tkinter import colorchooser -from test.support import requires, run_unittest, gc_collect +from test.support import requires, run_unittest from tkinter.test.support import AbstractTkTest requires('gui') From 968269944d3b2937eb7d36acbf927bf6041febf5 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 9 Feb 2020 15:41:04 -0500 Subject: [PATCH 06/13] Use different colors in tests --- .../test/test_tkinter/test_colorchooser.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index 2e49a9a6dcd0e5..ad2dddcfe8fb69 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -11,29 +11,29 @@ class ChooserTest(AbstractTkTest, unittest.TestCase): @classmethod def setUpClass(cls): AbstractTkTest.setUpClass.__func__(cls) - cls.cc = colorchooser.Chooser(initialcolor='red') + cls.cc = colorchooser.Chooser(initialcolor='dark blue slate') def test_fixoptions(self): cc = self.cc cc._fixoptions() - self.assertEqual(cc.options['initialcolor'], 'red') + self.assertEqual(cc.options['initialcolor'], 'dark blue slate') - cc.options['initialcolor'] = '#ffff00000000' + cc.options['initialcolor'] = '#D2D269691E1E' cc._fixoptions() - self.assertEqual(cc.options['initialcolor'], '#ffff00000000') + self.assertEqual(cc.options['initialcolor'], '#D2D269691E1E') - cc.options['initialcolor'] = (255, 0, 0) + cc.options['initialcolor'] = (210, 105, 30) cc._fixoptions() - self.assertEqual(cc.options['initialcolor'], '#ff0000') + self.assertEqual(cc.options['initialcolor'], '#d2691e') def test_fixresult(self): cc = self.cc self.assertEqual(cc._fixresult(self.root, ()), (None, None)) self.assertEqual(cc._fixresult(self.root, ''), (None, None)) - self.assertEqual(cc._fixresult(self.root, 'red'), - ((255, 0, 0), 'red')) - self.assertEqual(cc._fixresult(self.root, '#ff0000'), - ((255, 0, 0), '#ff0000')) + self.assertEqual(cc._fixresult(self.root, 'chocolate'), + ((210, 105, 30), 'chocolate')) + self.assertEqual(cc._fixresult(self.root, '#2E8B57'), + ((46, 139, 87), '#2E8B57')) tests_gui = (ChooserTest, ) From bd068c83c2c8516f4c6a7467fd93b3d276f008a7 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 9 Feb 2020 19:51:40 -0500 Subject: [PATCH 07/13] Try a different color for Ubuntu test --- Lib/tkinter/test/test_tkinter/test_colorchooser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index ad2dddcfe8fb69..1e0508594926fb 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -32,8 +32,8 @@ def test_fixresult(self): self.assertEqual(cc._fixresult(self.root, ''), (None, None)) self.assertEqual(cc._fixresult(self.root, 'chocolate'), ((210, 105, 30), 'chocolate')) - self.assertEqual(cc._fixresult(self.root, '#2E8B57'), - ((46, 139, 87), '#2E8B57')) + self.assertEqual(cc._fixresult(self.root, '#e9ff20'), + ((233, 255, 32), '#e9ff20')) tests_gui = (ChooserTest, ) From e39e826546e6f6f66356948a6006d031eb398548 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Tue, 11 Feb 2020 07:16:41 -0500 Subject: [PATCH 08/13] Try a different color for Ubuntu test --- Lib/tkinter/test/test_tkinter/test_colorchooser.py | 4 ++-- Lib/tkinter/test/test_tkinter/test_misc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index 1e0508594926fb..6cf2016b1cae33 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -32,8 +32,8 @@ def test_fixresult(self): self.assertEqual(cc._fixresult(self.root, ''), (None, None)) self.assertEqual(cc._fixresult(self.root, 'chocolate'), ((210, 105, 30), 'chocolate')) - self.assertEqual(cc._fixresult(self.root, '#e9ff20'), - ((233, 255, 32), '#e9ff20')) + self.assertEqual(cc._fixresult(self.root, '#1e90ff'), + ((30, 144, 255), '#1e90ff')) tests_gui = (ChooserTest, ) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 45a65fa24ce140..64d49256fe21bf 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -200,7 +200,7 @@ def test_winfo_rgb(self): self.assertEqual(rgb('red'), (65535, 0, 0)) self.assertEqual(rgb('dark slate blue'), (18504, 15677, 35723)) # #RGB - extends each 4-bit hex value to be 16-bit. - self.assertEqual(rgb('#4CE'), (0x4444, 0xCCCC, 0xEEEE)) + self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF)) # #RRGGBB - extends each 8-bit hex value to be 16-bit. self.assertEqual(rgb('#483d8b'), (0x4848, 0x3d3d, 0x8b8b)) # #RRRGGGBBB - uses 2 highest order bits for each color. From d4651424fa4b713dd4959923ced29db8cef35542 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Jan 2021 14:41:44 +0200 Subject: [PATCH 09/13] Apply suggestions from code review --- Lib/tkinter/test/test_tkinter/test_colorchooser.py | 4 ++-- Lib/tkinter/test/test_tkinter/test_misc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index d3a5eac7dcfbbf..738148492cb89e 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -35,8 +35,8 @@ def test_fixresult(self): self.assertEqual(cc._fixresult(self.root, ''), (None, None)) self.assertEqual(cc._fixresult(self.root, 'chocolate'), ((210, 105, 30), 'chocolate')) - self.assertEqual(cc._fixresult(self.root, '#1e90ff'), - ((30, 144, 255), '#1e90ff')) + self.assertEqual(cc._fixresult(self.root, '#dc144c'), + ((220, 20, 76), '#dc144c')) class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 133ef92ec03b57..2822fc270fb43c 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -202,7 +202,7 @@ def test_winfo_rgb(self): # #RGB - extends each 4-bit hex value to be 16-bit. self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF)) # #RRGGBB - extends each 8-bit hex value to be 16-bit. - self.assertEqual(rgb('#483d8b'), (0x4848, 0x3d3d, 0x8b8b)) + self.assertEqual(rgb('#dc143c'), (0xdcdc, 0x1414, 0x3c3c)) # #RRRGGGBBB - uses 2 highest order bits for each color. self.assertEqual(rgb('#123456789'), (0x1212, 0x4545, 0x7878)) # #RRRRGGGGBBBB - uses 2 highest order bits for each color. From 5b325b3e5b24109cc9e70270a22d30fd91549a75 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Jan 2021 15:18:11 +0200 Subject: [PATCH 10/13] Apply suggestions from code review --- Lib/tkinter/test/test_tkinter/test_colorchooser.py | 4 ++-- Lib/tkinter/test/test_tkinter/test_misc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_colorchooser.py b/Lib/tkinter/test/test_tkinter/test_colorchooser.py index 738148492cb89e..41da86c2adef49 100644 --- a/Lib/tkinter/test/test_tkinter/test_colorchooser.py +++ b/Lib/tkinter/test/test_tkinter/test_colorchooser.py @@ -35,8 +35,8 @@ def test_fixresult(self): self.assertEqual(cc._fixresult(self.root, ''), (None, None)) self.assertEqual(cc._fixresult(self.root, 'chocolate'), ((210, 105, 30), 'chocolate')) - self.assertEqual(cc._fixresult(self.root, '#dc144c'), - ((220, 20, 76), '#dc144c')) + self.assertEqual(cc._fixresult(self.root, '#4a3c8c'), + ((74, 60, 140), '#4a3c8c')) class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 2822fc270fb43c..5b15abd9c80310 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -202,7 +202,7 @@ def test_winfo_rgb(self): # #RGB - extends each 4-bit hex value to be 16-bit. self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF)) # #RRGGBB - extends each 8-bit hex value to be 16-bit. - self.assertEqual(rgb('#dc143c'), (0xdcdc, 0x1414, 0x3c3c)) + self.assertEqual(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c)) # #RRRGGGBBB - uses 2 highest order bits for each color. self.assertEqual(rgb('#123456789'), (0x1212, 0x4545, 0x7878)) # #RRRRGGGGBBBB - uses 2 highest order bits for each color. From c092dbfa3af94a3ea22895c615d136d30f2acfdb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Jan 2021 16:11:32 +0200 Subject: [PATCH 11/13] Update Lib/tkinter/test/test_tkinter/test_misc.py --- Lib/tkinter/test/test_tkinter/test_misc.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 5b15abd9c80310..c355785ccf69e5 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -203,10 +203,8 @@ def test_winfo_rgb(self): self.assertEqual(rgb('#F0F'), (0xFFFF, 0x0000, 0xFFFF)) # #RRGGBB - extends each 8-bit hex value to be 16-bit. self.assertEqual(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c)) - # #RRRGGGBBB - uses 2 highest order bits for each color. - self.assertEqual(rgb('#123456789'), (0x1212, 0x4545, 0x7878)) - # #RRRRGGGGBBBB - uses 2 highest order bits for each color. - self.assertEqual(rgb('#123456789abc'), (0x1212, 0x5656, 0x9a9a)) + # #RRRRGGGGBBBB + self.assertEqual(rgb('#dcdc14143c3c'), (0xdcdc, 0x1414, 0x3c3c)) # Invalid string. with self.assertRaises(tkinter.TclError): rgb('#123456789a') From 8dcbfa1369e8e8a0edb255a7544cd68faa5266f6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Jan 2021 19:57:00 +0200 Subject: [PATCH 12/13] Update Lib/tkinter/__init__.py Co-authored-by: Terry Jan Reedy --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index cd69ad55b53ff0..c23a117b412256 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1189,7 +1189,7 @@ def winfo_reqwidth(self): self.tk.call('winfo', 'reqwidth', self._w)) def winfo_rgb(self, color): - """Return a tuple of the RGB values for color in this widget.""" + """Return a tuple of integer RGB values in range(65536) for color in this widget.""" return self._getints( self.tk.call('winfo', 'rgb', self._w, color)) From b968e028aa486fab56e96e4c9115123ef075f3fd Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Jan 2021 20:31:28 +0200 Subject: [PATCH 13/13] Update Lib/tkinter/test/test_tkinter/test_misc.py --- Lib/tkinter/test/test_tkinter/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index c355785ccf69e5..f6e5b4db1ae1fb 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -204,7 +204,7 @@ def test_winfo_rgb(self): # #RRGGBB - extends each 8-bit hex value to be 16-bit. self.assertEqual(rgb('#4a3c8c'), (0x4a4a, 0x3c3c, 0x8c8c)) # #RRRRGGGGBBBB - self.assertEqual(rgb('#dcdc14143c3c'), (0xdcdc, 0x1414, 0x3c3c)) + self.assertEqual(rgb('#dede14143939'), (0xdede, 0x1414, 0x3939)) # Invalid string. with self.assertRaises(tkinter.TclError): rgb('#123456789a')