[Python-checkins] cpython (merge 3.2 -> 3.2): Merge heads

serhiy.storchaka python-checkins at python.org
Wed Jan 2 09:53:07 CET 2013


http://hg.python.org/cpython/rev/94234055552d
changeset:   81222:94234055552d
branch:      3.2
parent:      81215:7938847b2641
parent:      81219:956cfe53a99f
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Jan 02 10:32:13 2013 +0200
summary:
  Merge heads

files:
  Lib/tkinter/__init__.py                    |   2 +-
  Lib/tkinter/test/test_tkinter/test_misc.py |  45 ++++++++++
  Misc/NEWS                                  |   2 +
  3 files changed, 48 insertions(+), 1 deletions(-)


diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -380,7 +380,7 @@
         background, highlightColor, selectForeground,
         disabledForeground, insertBackground, troughColor."""
         self.tk.call(('tk_setPalette',)
-              + _flatten(args) + _flatten(kw.items()))
+              + _flatten(args) + _flatten(list(kw.items())))
     def tk_menuBar(self, *args):
         """Do not use. Needed in Tk 3.6 and earlier."""
         pass # obsolete since Tk 4.0
diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py
new file mode 100644
--- /dev/null
+++ b/Lib/tkinter/test/test_tkinter/test_misc.py
@@ -0,0 +1,45 @@
+import unittest
+import tkinter
+from tkinter import ttk
+from test import support
+
+support.requires('gui')
+
+class MiscTest(unittest.TestCase):
+
+    def setUp(self):
+        self.root = ttk.setup_master()
+
+    def test_tk_setPalette(self):
+        root = self.root
+        root.tk_setPalette('black')
+        self.assertEqual(root['background'], 'black')
+        root.tk_setPalette('white')
+        self.assertEqual(root['background'], 'white')
+        self.assertRaisesRegex(tkinter.TclError,
+                '^unknown color name "spam"$',
+                root.tk_setPalette, 'spam')
+
+        root.tk_setPalette(background='black')
+        self.assertEqual(root['background'], 'black')
+        root.tk_setPalette(background='blue', highlightColor='yellow')
+        self.assertEqual(root['background'], 'blue')
+        self.assertEqual(root['highlightcolor'], 'yellow')
+        root.tk_setPalette(background='yellow', highlightColor='blue')
+        self.assertEqual(root['background'], 'yellow')
+        self.assertEqual(root['highlightcolor'], 'blue')
+        self.assertRaisesRegex(tkinter.TclError,
+                '^unknown color name "spam"$',
+                root.tk_setPalette, background='spam')
+        self.assertRaisesRegex(tkinter.TclError,
+                '^must specify a background color$',
+                root.tk_setPalette, spam='white')
+        self.assertRaisesRegex(tkinter.TclError,
+                '^must specify a background color$',
+                root.tk_setPalette, highlightColor='blue')
+
+
+tests_gui = (MiscTest, )
+
+if __name__ == "__main__":
+    support.run_unittest(*tests_gui)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -189,6 +189,8 @@
 Library
 -------
 
+- Issue #16541: tk_setPalette() now works with keyword arguments.
+
 - Issue #16820: In configparser, `parser.popitem()` no longer raises ValueError.
   This makes `parser.clean()` work correctly.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list