[Python-checkins] bpo-23831: Add moveto method to the tkinter.Canvas widget. (GH-9768)
Serhiy Storchaka
webhook-mailer at python.org
Fri Oct 12 12:44:14 EDT 2018
https://github.com/python/cpython/commit/bf034715db9d6e1603ea432d40041e5577ed3332
commit: bf034715db9d6e1603ea432d40041e5577ed3332
branch: master
author: Juliette Monsel <j4321 at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018年10月12日T19:44:10+03:00
summary:
bpo-23831: Add moveto method to the tkinter.Canvas widget. (GH-9768)
files:
A Misc/NEWS.d/next/Library/2018-10-09-15-44-04.bpo-23831.2CL7lL.rst
M Doc/whatsnew/3.8.rst
M Lib/tkinter/__init__.py
M Lib/tkinter/test/test_tkinter/test_widgets.py
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index d9c3f1bd7dd6..bd3283caadb8 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -177,6 +177,10 @@ Added methods :meth:`~tkinter.Spinbox.selection_from`,
in the :class:`tkinter.Spinbox` class.
(Contributed by Juliette Monsel in :issue:`34829`.)
+Added method :meth:`~tkinter.Canvas.moveto`
+in the :class:`tkinter.Canvas` class.
+(Contributed by Juliette Monsel in :issue:`23831`.)
+
venv
----
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index fa015ff12e06..1dc411884511 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2914,6 +2914,15 @@ def move(self, *args):
"""Move an item TAGORID given in ARGS."""
self.tk.call((self._w, 'move') + args)
+ def moveto(self, tagOrId, x='', y=''):
+ """Move the items given by TAGORID in the canvas coordinate
+ space so that the first coordinate pair of the bottommost
+ item with tag TAGORID is located at position (X,Y).
+ X and Y may be the empty string, in which case the
+ corresponding coordinate will be unchanged. All items matching
+ TAGORID remain in the same positions relative to each other."""
+ self.tk.call(self._w, 'moveto', tagOrId, x, y)
+
def postscript(self, cnf={}, **kw):
"""Print the contents of the canvas to a postscript
file. Valid options: colormap, colormode, file, fontmap,
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
index c068a9de2d77..12a0fbeeeee1 100644
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -745,6 +745,29 @@ def test_yscrollincrement(self):
self.checkPixelsParam(widget, 'yscrollincrement',
10, 0, 11.2, 13.6, -10, '0.1i')
+ @requires_tcl(8, 6)
+ def test_moveto(self):
+ widget = self.create()
+ i1 = widget.create_rectangle(1, 1, 20, 20, tags='group')
+ i2 = widget.create_rectangle(30, 30, 50, 70, tags='group')
+ x1, y1, _, _ = widget.bbox(i1)
+ x2, y2, _, _ = widget.bbox(i2)
+ widget.moveto('group', 200, 100)
+ x1_2, y1_2, _, _ = widget.bbox(i1)
+ x2_2, y2_2, _, _ = widget.bbox(i2)
+ self.assertEqual(x1_2, 200)
+ self.assertEqual(y1_2, 100)
+ self.assertEqual(x2 - x1, x2_2 - x1_2)
+ self.assertEqual(y2 - y1, y2_2 - y1_2)
+ widget.tag_lower(i2, i1)
+ widget.moveto('group', y=50)
+ x1_3, y1_3, _, _ = widget.bbox(i1)
+ x2_3, y2_3, _, _ = widget.bbox(i2)
+ self.assertEqual(y2_3, 50)
+ self.assertEqual(x2_3, x2_2)
+ self.assertEqual(x2_2 - x1_2, x2_3 - x1_3)
+ self.assertEqual(y2_2 - y1_2, y2_3 - y1_3)
+
@add_standard_options(IntegerSizeTests, StandardOptionsTests)
class ListboxTest(AbstractWidgetTest, unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2018-10-09-15-44-04.bpo-23831.2CL7lL.rst b/Misc/NEWS.d/next/Library/2018-10-09-15-44-04.bpo-23831.2CL7lL.rst
new file mode 100644
index 000000000000..de12407b4ffe
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-09-15-44-04.bpo-23831.2CL7lL.rst
@@ -0,0 +1,2 @@
+Add ``moveto()`` method to the ``tkinter.Canvas`` widget. Patch by Juliette
+Monsel.
More information about the Python-checkins
mailing list