From 9ab78c27e95133cc5224abeeca78db19ceccc139 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 18:27:11 +0800 Subject: [PATCH 01/10] feat: add parameter `**kw` to `Misc.after` and `Misc.after_idle` --- Lib/tkinter/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index dd7b3e138f4236..bfec04bb6c1e6e 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -847,7 +847,7 @@ def tk_focusPrev(self): if not name: return None return self._nametowidget(name) - def after(self, ms, func=None, *args): + def after(self, ms, func=None, *args, **kw): """Call function once after given time. MS specifies the time in milliseconds. FUNC gives the @@ -861,7 +861,7 @@ def after(self, ms, func=None, *args): else: def callit(): try: - func(*args) + func(*args, **kw) finally: try: self.deletecommand(name) @@ -875,13 +875,13 @@ def callit(): name = self._register(callit) return self.tk.call('after', ms, name) - def after_idle(self, func, *args): + def after_idle(self, func, *args, **kw): """Call FUNC once if the Tcl main loop has no event to process. Return an identifier to cancel the scheduling with after_cancel.""" - return self.after('idle', func, *args) + return self.after('idle', func, *args, **kw) def after_cancel(self, id): """Cancel scheduling of function identified with ID. From d6e7a18c50c054d48a2a9cee483d3d35c536ebba Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 10:52:49 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst diff --git a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst new file mode 100644 index 00000000000000..1a64813f3f6e38 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst @@ -0,0 +1 @@ +Add ``**kw`` to ``tkinter.Misc.after`` and ``tkinter.Misc.after_idle``. From 8f314bb83e009d3b974bd8f07c1210f6c5458121 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 19:46:45 +0800 Subject: [PATCH 03/10] docs: add a What's New entry --- Doc/whatsnew/3.14.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 958efbe73c1c27..e8256d209bc3b6 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -514,6 +514,15 @@ sys from other interpreters than the one it's called in. +tkinter +------- + +* Add the argument ``**kw`` to method :meth:`tkinter.Misc.after` and + :meth:`tkinter.Misc.after_idle` so that the keyword argument can passed to + ``func`` Conveniently. + (Contributed by Zhikang Yan in :gh:`126899`.) + + unicodedata ----------- From 14fb23c31ebc182a31dffc33c496cdb4eca7da1e Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 20:00:55 +0800 Subject: [PATCH 04/10] test: add tests for `**kw` --- Lib/test/test_tkinter/test_misc.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_tkinter/test_misc.py b/Lib/test/test_tkinter/test_misc.py index 579ce2af9fa0bf..475edcbd5338a7 100644 --- a/Lib/test/test_tkinter/test_misc.py +++ b/Lib/test/test_tkinter/test_misc.py @@ -123,9 +123,9 @@ def test_tk_setPalette(self): def test_after(self): root = self.root - def callback(start=0, step=1): + def callback(start=0, step=1, *, end=0): nonlocal count - count = start + step + count = start + step + end # Without function, sleeps for ms. self.assertIsNone(root.after(1)) @@ -161,12 +161,18 @@ def callback(start=0, step=1): root.update() # Process all pending events. self.assertEqual(count, 53) + # Set up with callback with keyword args. + count = 0 + timer1 = root.after(0, callback, 42, step=11, end=1) + root.update() # Process all pending events. + self.assertEqual(count, 54) + def test_after_idle(self): root = self.root - def callback(start=0, step=1): + def callback(start=0, step=1, *, end=0): nonlocal count - count = start + step + count = start + step + end # Set up with callback with no args. count = 0 @@ -193,6 +199,12 @@ def callback(start=0, step=1): with self.assertRaises(tkinter.TclError): root.tk.call(script) + # Set up with callback with keyword args. + count = 0 + idle1 = root.after_idle(callback, 42, step=11, end=1) + root.update() # Process all pending events. + self.assertEqual(count, 54) + def test_after_cancel(self): root = self.root From 6966d3c2996e84d051d1b47f4a9bb709100fcfb3 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 20:05:34 +0800 Subject: [PATCH 05/10] chore: change ACKS --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 08cd293eac3835..784cc83c9e1d39 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -2078,6 +2078,7 @@ Arnon Yaari Alakshendra Yadav Hirokazu Yamamoto Masayuki Yamamoto +Zhikang Yan Jingchen Ye Ka-Ping Yee Chi Hsuan Yen From ccc0060622a8d82f4c68a08b4cbb47d49e650ad3 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 20:14:12 +0800 Subject: [PATCH 06/10] docs: change What's new --- Doc/whatsnew/3.14.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index e8256d209bc3b6..0c9982653e7ef8 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -517,9 +517,9 @@ sys tkinter ------- -* Add the argument ``**kw`` to method :meth:`tkinter.Misc.after` and - :meth:`tkinter.Misc.after_idle` so that the keyword argument can passed to - ``func`` Conveniently. +* Add the argument ``**kw`` to method :meth:`!after` and method + :meth:`!after_idle` of :mod:`tkinter` widgets so that the keyword argument + can passed to ``func`` Conveniently. (Contributed by Zhikang Yan in :gh:`126899`.) From e61dfb80f432d158184d0fb25e4ec9b4f63995a9 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sat, 16 Nov 2024 20:21:01 +0800 Subject: [PATCH 07/10] docs: fix a typo --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 0c9982653e7ef8..941c8b6f5daa6d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -519,7 +519,7 @@ tkinter * Add the argument ``**kw`` to method :meth:`!after` and method :meth:`!after_idle` of :mod:`tkinter` widgets so that the keyword argument - can passed to ``func`` Conveniently. + can passed to ``func`` conveniently. (Contributed by Zhikang Yan in :gh:`126899`.) From c96875e5c15db5b3eb4818357b52908c5987ff3b Mon Sep 17 00:00:00 2001 From: Zhikang Yan <2951256653@qq.com> Date: Mon, 18 Nov 2024 19:20:35 +0800 Subject: [PATCH 08/10] Update Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst Co-authored-by: Serhiy Storchaka --- .../next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst index 1a64813f3f6e38..afd47b541ab38e 100644 --- a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst +++ b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst @@ -1 +1 @@ -Add ``**kw`` to ``tkinter.Misc.after`` and ``tkinter.Misc.after_idle``. +Add the var-positional parameter to :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle`. From be1c1d4946bc2a61789e979359d550aaa4a15b5f Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Mon, 18 Nov 2024 19:37:35 +0800 Subject: [PATCH 09/10] Improve whatsnew --- Doc/whatsnew/3.14.rst | 5 ++--- .../Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 941c8b6f5daa6d..35865094970957 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -517,9 +517,8 @@ sys tkinter ------- -* Add the argument ``**kw`` to method :meth:`!after` and method - :meth:`!after_idle` of :mod:`tkinter` widgets so that the keyword argument - can passed to ``func`` conveniently. +* The methods :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle` + now support passing keyword arguments to the function. (Contributed by Zhikang Yan in :gh:`126899`.) diff --git a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst index afd47b541ab38e..3bb0c2ce629280 100644 --- a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst +++ b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst @@ -1 +1 @@ -Add the var-positional parameter to :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle`. +Add the var-keyword parameter to :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle`. From b99e97e4ce48112b9fd4162a24f02b70162d4e63 Mon Sep 17 00:00:00 2001 From: Xiaokang2022 <2951256653@qq.com> Date: Sun, 1 Dec 2024 19:55:16 +0800 Subject: [PATCH 10/10] docs: Improve changelog and whatsnew --- Doc/whatsnew/3.14.rst | 4 ++-- .../Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 35865094970957..f92aa931bf2ca1 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -517,8 +517,8 @@ sys tkinter ------- -* The methods :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle` - now support passing keyword arguments to the function. +* Make tkinter widget methods :meth:`!after` and :meth:`!after_idle` accept + arguments passed by keyword. (Contributed by Zhikang Yan in :gh:`126899`.) diff --git a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst index 3bb0c2ce629280..c1a0ed6438135d 100644 --- a/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst +++ b/Misc/NEWS.d/next/Library/2024-11-16-10-52-48.gh-issue-126899.GFnfBt.rst @@ -1 +1,2 @@ -Add the var-keyword parameter to :meth:`!tkinter.Misc.after` and :meth:`!tkinter.Misc.after_idle`. +Make tkinter widget methods :meth:`!after` and :meth:`!after_idle` accept +arguments passed by keyword.