FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-94473: Flatten arguments in tkinter.Canvas.coords() by serhiy-storchaka · Pull Request #98479 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions Doc/whatsnew/3.12.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_tkinter/test_widgets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,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))
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,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))]
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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), ...]``.

Back | FazBrowse Home | New Git URL