]> granicus.if.org Git - python/commitdiff
Issue #16541: tk_setPalette() now works with keyword arguments.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 1 Jan 2013 22:03:58 +0000 (00:03 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 1 Jan 2013 22:03:58 +0000 (00:03 +0200)
Added a test for tk_setPalette().

Lib/tkinter/__init__.py
Lib/tkinter/test/test_tkinter/test_misc.py [new file with mode: 0644]
Misc/NEWS

index f2cb60f4b5e5cdf04a378ed9a5217b406a2b1479..3ba4bb00ca9bc85adcaa56e1b8964e2b506a5139 100644 (file)
@@ -380,7 +380,7 @@ class Misc:
         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 (file)
index 0000000..d325b31
--- /dev/null
@@ -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)
index b9b14a79ba63077fd92c5aa04d0f37102f964995..5ef30afc5d8e5c93378d6dacda2141f4adf4bad1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -189,6 +189,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #16541: tk_setPalette() now works with keyword arguments.
+
 - Issue #16819: IDLE method completion now correctly works for bytes literals.
 
 - Issue #9586: Redefine SEM_FAILED on MacOSX to keep compiler happy.