Skip to content

Commit 4e6c232

Browse files
pythongh-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), ...]".
1 parent ff173ed commit 4e6c232

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎Doc/whatsnew/3.12.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ threading
182182
profiling functions in all running threads in addition to the calling one.
183183
(Contributed by Pablo Galindo in :gh:`93503`.)
184184

185+
tkinter
186+
-------
187+
188+
* :meth:`tkinter.Canvas.coords` now flattens its arguments.
189+
It now accepts not only coordinates as separate arguments
190+
(``x1, y1, x2, y2, ...``) and a sequence of coordinates
191+
(``[x1, y1, x2, y2, ...]``), but also coordinates grouped in pairs
192+
(``(x1, y1), (x2, y2), ...`` and ``[(x1, y1), (x2, y2), ...]``),
193+
like ``create_*()`` methods.
194+
(Contributed by Serhiy Storchaka in :gh:`94473`.)
195+
185196
unicodedata
186197
-----------
187198

‎Lib/test/test_tkinter/test_widgets.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ def test_coords(self):
900900
c.coords(i, [21, 31, 41, 51, 61, 11])
901901
self.assertEqual(c.coords(i), [21.0, 31.0, 41.0, 51.0, 61.0, 11.0])
902902

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

‎Lib/tkinter/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ def canvasy(self, screeny, gridspacing=None):
28162816

28172817
def coords(self, *args):
28182818
"""Return a list of coordinates for the item given in ARGS."""
2819-
# XXX Should use _flatten on args
2819+
args = _flatten(args)
28202820
return [self.tk.getdouble(x) for x in
28212821
self.tk.splitlist(
28222822
self.tk.call((self._w, 'coords') + args))]
Lines changed: 3 additions & 0 deletions
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)