Skip to content

Commit 9bc80da

Browse files
gh-94473: Flatten arguments in tkinter.Canvas.coords() (GH-98479)
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), ...]".
1 parent 6fba031 commit 9bc80da

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

Doc/whatsnew/3.12.rst

+11
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,17 @@ threading
532532
profiling functions in all running threads in addition to the calling one.
533533
(Contributed by Pablo Galindo in :gh:`93503`.)
534534

535+
tkinter
536+
-------
537+
538+
* ``tkinter.Canvas.coords()`` now flattens its arguments.
539+
It now accepts not only coordinates as separate arguments
540+
(``x1, y1, x2, y2, ...``) and a sequence of coordinates
541+
(``[x1, y1, x2, y2, ...]``), but also coordinates grouped in pairs
542+
(``(x1, y1), (x2, y2), ...`` and ``[(x1, y1), (x2, y2), ...]``),
543+
like ``create_*()`` methods.
544+
(Contributed by Serhiy Storchaka in :gh:`94473`.)
545+
535546
types
536547
-----
537548

Lib/test/test_tkinter/test_widgets.py

+6
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,12 @@ def test_coords(self):
901901
c.coords(i, [21, 31, 41, 51, 61, 11])
902902
self.assertEqual(c.coords(i), [21.0, 31.0, 41.0, 51.0, 61.0, 11.0])
903903

904+
c.coords(i, (22, 32), (42, 52), (62, 12))
905+
self.assertEqual(c.coords(i), [22.0, 32.0, 42.0, 52.0, 62.0, 12.0])
906+
907+
c.coords(i, [(23, 33), (43, 53), (63, 13)])
908+
self.assertEqual(c.coords(i), [23.0, 33.0, 43.0, 53.0, 63.0, 13.0])
909+
904910
c.coords(i, 20, 30, 60, 10)
905911
self.assertEqual(c.coords(i), [20.0, 30.0, 60.0, 10.0])
906912
self.assertEqual(c.bbox(i), (18, 8, 62, 32))

Lib/tkinter/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,7 @@ def canvasy(self, screeny, gridspacing=None):
28172817

28182818
def coords(self, *args):
28192819
"""Return a list of coordinates for the item given in ARGS."""
2820-
# XXX Should use _flatten on args
2820+
args = _flatten(args)
28212821
return [self.tk.getdouble(x) for x in
28222822
self.tk.splitlist(
28232823
self.tk.call((self._w, 'coords') + args))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flatten arguments in :meth:`tkinter.Canvas.coords`. It now accepts not only
2+
``x1, y1, x2, y2, ...`` and ``[x1, y1, x2, y2, ...]``, but also ``(x1, y1),
3+
(x2, y2), ...`` and ``[(x1, y1), (x2, y2), ...]``.

0 commit comments

Comments
 (0)