From 4e6c232332e1a4b8fa6e9d8a14e5c9cbb292f662 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 20 Oct 2022 14:04:40 +0300 Subject: [PATCH 1/2] gh-94473: Flatten arguments in tkinter.Canvas.coords() It now accepts not only "x1, y1, x2, y2, ..." and "[x1, y1, x2, y2, ...]", but also "(x1, y1), (x2, y2), ..." and "[(x1, y1), (x2, y2), ...]". --- Doc/whatsnew/3.12.rst | 11 +++++++++++ Lib/test/test_tkinter/test_widgets.py | 6 ++++++ Lib/tkinter/__init__.py | 2 +- .../2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 525efc405c8520..9f7352f3940894 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -182,6 +182,17 @@ threading profiling functions in all running threads in addition to the calling one. (Contributed by Pablo Galindo in :gh:`93503`.) +tkinter +------- + +* :meth:`tkinter.Canvas.coords` now flattens its arguments. + It now accepts not only coordinates as separate arguments + (``x1, y1, x2, y2, ...``) and a sequence of coordinates + (``[x1, y1, x2, y2, ...]``), but also coordinates grouped in pairs + (``(x1, y1), (x2, y2), ...`` and ``[(x1, y1), (x2, y2), ...]``), + like ``create_*()`` methods. + (Contributed by Serhiy Storchaka in :gh:`94473`.) + unicodedata ----------- diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index 6fde93cbecc73f..8ac0cdd6be2a1e 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -900,6 +900,12 @@ def test_coords(self): c.coords(i, [21, 31, 41, 51, 61, 11]) self.assertEqual(c.coords(i), [21.0, 31.0, 41.0, 51.0, 61.0, 11.0]) + c.coords(i, (22, 32), (42, 52), (62, 12)) + self.assertEqual(c.coords(i), [22.0, 32.0, 42.0, 52.0, 62.0, 12.0]) + + c.coords(i, [(23, 33), (43, 53), (63, 13)]) + self.assertEqual(c.coords(i), [23.0, 33.0, 43.0, 53.0, 63.0, 13.0]) + c.coords(i, 20, 30, 60, 10) self.assertEqual(c.coords(i), [20.0, 30.0, 60.0, 10.0]) self.assertEqual(c.bbox(i), (18, 8, 62, 32)) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index a8e7bf490ad463..5eb8e73b3d3e35 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -2816,7 +2816,7 @@ def canvasy(self, screeny, gridspacing=None): def coords(self, *args): """Return a list of coordinates for the item given in ARGS.""" - # XXX Should use _flatten on args + args = _flatten(args) return [self.tk.getdouble(x) for x in self.tk.splitlist( self.tk.call((self._w, 'coords') + args))] diff --git a/Misc/NEWS.d/next/Library/2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst b/Misc/NEWS.d/next/Library/2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst new file mode 100644 index 00000000000000..f70722a6f0f69c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst @@ -0,0 +1,3 @@ +Flatten arguments in :meth:`tkinter.Canvas.coords`. It now accepts not only +``x1, y1, x2, y2, ...`` and ``[x1, y1, x2, y2, ...]``, but also ``(x1, y1), +(x2, y2), ...`` and ``[(x1, y1), (x2, y2), ...]``. From 2bbad710d1047716a27969124d8f0541cbee1960 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 22 May 2023 10:36:44 +0300 Subject: [PATCH 2/2] Silence Sphinx warning. --- Doc/whatsnew/3.12.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 74f1e1988b1c0c..efbd2ca3de122a 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -535,7 +535,7 @@ threading tkinter ------- -* :meth:`tkinter.Canvas.coords` now flattens its arguments. +* ``tkinter.Canvas.coords()`` now flattens its arguments. It now accepts not only coordinates as separate arguments (``x1, y1, x2, y2, ...``) and a sequence of coordinates (``[x1, y1, x2, y2, ...]``), but also coordinates grouped in pairs