Skip to content

Commit 471f093

Browse files
committed
Clearer tests for winfo_rgb.
1 parent 83574cd commit 471f093

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Lib/tkinter/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,16 +1045,7 @@ def winfo_reqwidth(self):
10451045
return self.tk.getint(
10461046
self.tk.call('winfo', 'reqwidth', self._w))
10471047
def winfo_rgb(self, color):
1048-
"""Return a tuple of the RGB values for color in this widget.
1049-
1050-
Args:
1051-
color: String representation of the color either as a name
1052-
or as # followed by 4-, 8-, 12-, or 16-bit hex values.
1053-
1054-
Returns:
1055-
A 3-tuple of ints in the range (0, 65535) of the red, green,
1056-
and blue intensities for color.
1057-
"""
1048+
"""Return a tuple of the RGB values for color in this widget."""
10581049
return self._getints(
10591050
self.tk.call('winfo', 'rgb', self._w, color))
10601051
def winfo_rootx(self):

Lib/tkinter/test/test_tkinter/test_misc.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,23 @@ def test_winfo_rgb(self):
162162

163163
# Color name.
164164
self.assertEqual(rgb('red'), (65535, 0, 0))
165-
# #RGB
166-
self.assertEqual(rgb('#f00'), (65535, 0, 0))
167-
# #RRGGBB
168-
self.assertEqual(rgb('#ff0000'), (65535, 0, 0))
169-
# #RRRGGGBBB
170-
self.assertEqual(rgb('#000fff000'), (0, 65535, 0))
171-
# #RRRRGGGGBBBB
172-
self.assertEqual(rgb('#ffff0000ffff'), (65535, 0, 65535))
165+
self.assertEqual(rgb('dark slate blue'), (18504, 15677, 35723))
166+
# #RGB - extends each 4-bit hex value to be 16-bit.
167+
self.assertEqual(rgb('#f00'),
168+
(int('ffff', 16), 0, 0))
169+
# #RRGGBB - extends each 8-bit hex value to be 16-bit.
170+
self.assertTrue(rgb('#483d8b') ==
171+
(int('4848', 16), int('3d3d', 16), int('8b8b', 16)) ==
172+
(18504, 15677, 35723)) # dark slate blue
173+
# #RRRGGGBBB - uses 2 highest order bits for each color.
174+
self.assertEqual(rgb('#123456789'),
175+
(int('1212', 16), int('4545', 16), int('7878', 16)))
176+
# #RRRRGGGGBBBB - uses 2 highest order bits for each color.
177+
self.assertEqual(rgb('#1234567800ff'),
178+
(int('1212', 16), int('5656', 16), int('0000', 16)))
179+
# Invalid string.
180+
with self.assertRaises(tkinter.TclError):
181+
rgb('#1234567890')
173182
# RGB triplet is invalid input.
174183
with self.assertRaises(tkinter.TclError):
175184
rgb((255, 0, 0))

0 commit comments

Comments
 (0)