From b70aac63927a563f2473aab25ca3b8a4ae02591e Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 23 Feb 2025 14:34:26 +0800 Subject: [PATCH 1/6] feat: Add default values to the parameters of the widget `tkinter.OptionMenu` --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 0baed8b569e40f..44c61ca66ab571 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="", 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 From 4bfbdb744f23a8419ad253ebd3078be64d0fdc80 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 06:49:28 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst 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..a3feb5cc0cce64 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst @@ -0,0 +1 @@ +Add default values to the parameters of widget :class:`OptionMenu` in :mod:`tkinter` From d7caccb915f65254807f67cf4b8a264e26bbaa7c Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 23 Feb 2025 14:56:25 +0800 Subject: [PATCH 3/6] docs: fix changelog --- .../next/Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a3feb5cc0cce64..417ad8c2e8f3ee 100644 --- 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 @@ -1 +1 @@ -Add default values to the parameters of widget :class:`OptionMenu` in :mod:`tkinter` +Add default values to the parameters of widget :class:`tkinter.OptionMenu`. From bd727655838d92ddb71adbb7e80b3e8952561797 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 23 Feb 2025 15:05:35 +0800 Subject: [PATCH 4/6] test: Add tests --- Lib/test/test_tkinter/test_widgets.py | 3 +++ 1 file changed, 3 insertions(+) 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)) From c69ec88bb14a69adb3246d975e32152cdcdbd4ca Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 23 Feb 2025 16:15:18 +0800 Subject: [PATCH 5/6] feat: Change default value of the parameter `variable` to `None` --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 44c61ca66ab571..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=None, 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 From d101cca6a7ce227af7dea6bb3666d99d932a06fe Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 23 Feb 2025 16:22:53 +0800 Subject: [PATCH 6/6] docs: Improve changelog --- Doc/whatsnew/3.14.rst | 3 +++ .../Library/2025-02-23-06-49-26.gh-issue-130356._VDYmg.rst | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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 index 417ad8c2e8f3ee..0887630125d276 100644 --- 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 @@ -1 +1,2 @@ -Add default values to the parameters of widget :class:`tkinter.OptionMenu`. +Add default values to the initialization parameters of class +:class:`!tkinter.OptionMenu`.