summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/tkinter/__init__.py2
-rw-r--r--Lib/tkinter/test/test_tkinter/test_widgets.py4
-rw-r--r--Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst2
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index a3378d0..1067ab6 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -3965,7 +3965,7 @@ class OptionMenu(Menubutton):
if 'command' in kwargs:
del kwargs['command']
if kwargs:
- raise TclError('unknown option -'+kwargs.keys()[0])
+ raise TclError('unknown option -'+next(iter(kwargs)))
menu.add_command(label=value,
command=_setit(variable, value, callback))
for v in values:
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
index 16e9d93..721e813 100644
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -307,6 +307,10 @@ class OptionMenuTest(MenubuttonTest, unittest.TestCase):
def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
return tkinter.OptionMenu(self.root, None, default, *values, **kwargs)
+ def test_bad_kwarg(self):
+ with self.assertRaisesRegex(TclError, r"^unknown option -image$"):
+ tkinter.OptionMenu(self.root, None, 'b', image='')
+
@add_standard_options(IntegerSizeTests, StandardOptionsTests)
class EntryTest(AbstractWidgetTest, unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst b/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst
new file mode 100644
index 0000000..d797374
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst
@@ -0,0 +1,2 @@
+Raise TclError instead of TypeError when an unknown option is passed to
+tkinter.OptionMenu.