]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94473: Flatten arguments in tkinter.Canvas.coords() (GH-98479)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 22 May 2023 08:54:41 +0000 (11:54 +0300)
committerGitHub <noreply@github.com>
Mon, 22 May 2023 08:54:41 +0000 (11:54 +0300)
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
Lib/test/test_tkinter/test_widgets.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2022-10-20-14-03-58.gh-issue-94473.pzGX73.rst [new file with mode: 0644]

index caf21078b9bd592fb9aa4386dee363d4b47f4a3b..efbd2ca3de122ae353928541e410fbb618489515 100644 (file)
@@ -532,6 +532,17 @@ threading
   profiling functions in all running threads in addition to the calling one.
   (Contributed by Pablo Galindo in :gh:`93503`.)
 
+tkinter
+-------
+
+* ``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`.)
+
 types
 -----
 
index b45245162f24462b376d185986ef0127058ceb2d..76cc16e5b977dee86e425a1f5a60b314523fbdec 100644 (file)
@@ -901,6 +901,12 @@ class CanvasTest(AbstractWidgetTest, unittest.TestCase):
         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))
index bf0b3b92155938c1ea86be62866c0980dd82c17b..c675c511e04533241c0299df37b1533c3de8aeb2 100644 (file)
@@ -2817,7 +2817,7 @@ class Canvas(Widget, XView, YView):
 
     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 (file)
index 0000000..f70722a
--- /dev/null
@@ -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), ...]``.