diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index eee9bc865357ee..c795a449a5d428 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -809,6 +809,9 @@ tkinter arguments passed by keyword. (Contributed by Zhikang Yan in :gh:`126899`.) +* Add default values to the initialization parameters of class + :class:`!tkinter.OptionMenu`. + (Contributed by Zhikang Yan in :gh:`130356`.) turtle ------ diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index f6e77973061956..9da99065603dec 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -354,6 +354,9 @@ def test_bad_kwarg(self): with self.assertRaisesRegex(TclError, r"^unknown option -image$"): tkinter.OptionMenu(self.root, None, 'b', image='') + def test_default_parameters(self): + tkinter.OptionMenu(self.root) + @add_configure_tests(IntegerSizeTests, StandardOptionsTests) class EntryTest(AbstractWidgetTest, unittest.TestCase): _rounds_pixels = (tk_version < (9, 0)) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 0baed8b569e40f..3728db95c2882c 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -4180,7 +4180,7 @@ def __call__(self, *args): class OptionMenu(Menubutton): """OptionMenu which allows the user to select a value from a menu.""" - def __init__(self, master, variable, value, *values, **kwargs): + def __init__(self, master=None, variable=None, value="", *values, **kwargs): """Construct an optionmenu widget with the parent MASTER, with the resource textvariable set to VARIABLE, the initially selected value VALUE, the other menu values VALUES and an additional diff --git a/Misc/NEWS.d/next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst b/Misc/NEWS.d/next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst new file mode 100644 index 00000000000000..0887630125d276 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst @@ -0,0 +1,2 @@ +Add default values to the initialization parameters of class +:class:`!tkinter.OptionMenu`.