Skip to content

Commit 0afa381

Browse files
Rename "from_" to "from_coords".
1 parent 09e382d commit 0afa381

File tree

5 files changed

+57
-54
lines changed

5 files changed

+57
-54
lines changed

Doc/library/tkinter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ option (other options are available as well).
983983
Added the :class:`!PhotoImage` method :meth:`!copy_replace` to copy a region
984984
from one image to other image, possibly with pixel zooming and/or
985985
subsampling.
986-
Add *from_* parameter to :class:`!PhotoImage` methods :meth:`!copy()`,
986+
Add *from_coords* parameter to :class:`!PhotoImage` methods :meth:`!copy()`,
987987
:meth:`!zoom()` and :meth:`!subsample()`.
988988
Add *zoom* and *subsample* parameters to :class:`!PhotoImage` method
989989
:meth:`!copy()`.

Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ tkinter
878878
* Add the :class:`!PhotoImage` method :meth:`!copy_replace` to copy a region
879879
from one image to other image, possibly with pixel zooming and/or
880880
subsampling.
881-
Add *from_* parameter to :class:`!PhotoImage` methods :meth:`!copy()`,
881+
Add *from_coords* parameter to :class:`!PhotoImage` methods :meth:`!copy()`,
882882
:meth:`!zoom()` and :meth:`!subsample()`.
883883
Add *zoom* and *subsample* parameters to :class:`!PhotoImage` method
884884
:meth:`!copy()`.

Lib/test/test_tkinter/test_images.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,29 +304,29 @@ def test_copy(self):
304304
self.assertEqual(image2.height(), 16)
305305
self.assertEqual(image2.get(4, 6), image.get(4, 6))
306306

307-
image2 = image.copy(from_=(2, 3, 14, 11))
307+
image2 = image.copy(from_coords=(2, 3, 14, 11))
308308
self.assertEqual(image2.width(), 12)
309309
self.assertEqual(image2.height(), 8)
310310
self.assertEqual(image2.get(0, 0), image.get(2, 3))
311311
self.assertEqual(image2.get(11, 7), image.get(13, 10))
312312
self.assertEqual(image2.get(2, 4), image.get(2+2, 4+3))
313313

314-
image2 = image.copy(from_=(2, 3, 14, 11), zoom=2)
314+
image2 = image.copy(from_coords=(2, 3, 14, 11), zoom=2)
315315
self.assertEqual(image2.width(), 24)
316316
self.assertEqual(image2.height(), 16)
317317
self.assertEqual(image2.get(0, 0), image.get(2, 3))
318318
self.assertEqual(image2.get(23, 15), image.get(13, 10))
319319
self.assertEqual(image2.get(2*2, 4*2), image.get(2+2, 4+3))
320320
self.assertEqual(image2.get(2*2+1, 4*2+1), image.get(6+2, 2+3))
321321

322-
image2 = image.copy(from_=(2, 3, 14, 11), subsample=2)
322+
image2 = image.copy(from_coords=(2, 3, 14, 11), subsample=2)
323323
self.assertEqual(image2.width(), 6)
324324
self.assertEqual(image2.height(), 4)
325325
self.assertEqual(image2.get(0, 0), image.get(2, 3))
326326
self.assertEqual(image2.get(5, 3), image.get(12, 9))
327327
self.assertEqual(image2.get(3, 2), image.get(3*2+2, 2*2+3))
328328

329-
image2 = image.copy(from_=(2, 3, 14, 11), subsample=2, zoom=3)
329+
image2 = image.copy(from_coords=(2, 3, 14, 11), subsample=2, zoom=3)
330330
self.assertEqual(image2.width(), 18)
331331
self.assertEqual(image2.height(), 12)
332332
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -346,7 +346,7 @@ def test_subsample(self):
346346
self.assertEqual(image2.height(), 8)
347347
self.assertEqual(image2.get(2, 3), image.get(4, 6))
348348

349-
image2 = image.subsample(2, from_=(2, 3, 14, 11))
349+
image2 = image.subsample(2, from_coords=(2, 3, 14, 11))
350350
self.assertEqual(image2.width(), 6)
351351
self.assertEqual(image2.height(), 4)
352352
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -367,7 +367,7 @@ def test_zoom(self):
367367
self.assertEqual(image2.get(8, 12), image.get(4, 6))
368368
self.assertEqual(image2.get(9, 13), image.get(4, 6))
369369

370-
image2 = image.zoom(2, from_=(2, 3, 14, 11))
370+
image2 = image.zoom(2, from_coords=(2, 3, 14, 11))
371371
self.assertEqual(image2.width(), 24)
372372
self.assertEqual(image2.height(), 16)
373373
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -384,7 +384,7 @@ def test_copy_replace(self):
384384
self.assertEqual(image2.get(4, 6), image.get(4, 6))
385385

386386
image2 = tkinter.PhotoImage(master=self.root)
387-
image2.copy_replace(image, from_=(2, 3, 14, 11))
387+
image2.copy_replace(image, from_coords=(2, 3, 14, 11))
388388
self.assertEqual(image2.width(), 12)
389389
self.assertEqual(image2.height(), 8)
390390
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -393,23 +393,23 @@ def test_copy_replace(self):
393393

394394
image2 = tkinter.PhotoImage(master=self.root)
395395
image2.copy_replace(image)
396-
image2.copy_replace(image, from_=(2, 3, 14, 11), shrink=True)
396+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), shrink=True)
397397
self.assertEqual(image2.width(), 12)
398398
self.assertEqual(image2.height(), 8)
399399
self.assertEqual(image2.get(0, 0), image.get(2, 3))
400400
self.assertEqual(image2.get(11, 7), image.get(13, 10))
401401
self.assertEqual(image2.get(2, 4), image.get(2+2, 4+3))
402402

403403
image2 = tkinter.PhotoImage(master=self.root)
404-
image2.copy_replace(image, from_=(2, 3, 14, 11), to=(3, 6))
404+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), to=(3, 6))
405405
self.assertEqual(image2.width(), 15)
406406
self.assertEqual(image2.height(), 14)
407407
self.assertEqual(image2.get(0+3, 0+6), image.get(2, 3))
408408
self.assertEqual(image2.get(11+3, 7+6), image.get(13, 10))
409409
self.assertEqual(image2.get(2+3, 4+6), image.get(2+2, 4+3))
410410

411411
image2 = tkinter.PhotoImage(master=self.root)
412-
image2.copy_replace(image, from_=(2, 3, 14, 11), to=(0, 0, 100, 50))
412+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), to=(0, 0, 100, 50))
413413
self.assertEqual(image2.width(), 100)
414414
self.assertEqual(image2.height(), 50)
415415
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -420,7 +420,7 @@ def test_copy_replace(self):
420420
self.assertEqual(image2.get(2, 4+8*3), image.get(2+2, 4+3))
421421

422422
image2 = tkinter.PhotoImage(master=self.root)
423-
image2.copy_replace(image, from_=(2, 3, 14, 11), zoom=2)
423+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), zoom=2)
424424
self.assertEqual(image2.width(), 24)
425425
self.assertEqual(image2.height(), 16)
426426
self.assertEqual(image2.get(0, 0), image.get(2, 3))
@@ -429,15 +429,15 @@ def test_copy_replace(self):
429429
self.assertEqual(image2.get(2*2+1, 4*2+1), image.get(6+2, 2+3))
430430

431431
image2 = tkinter.PhotoImage(master=self.root)
432-
image2.copy_replace(image, from_=(2, 3, 14, 11), subsample=2)
432+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), subsample=2)
433433
self.assertEqual(image2.width(), 6)
434434
self.assertEqual(image2.height(), 4)
435435
self.assertEqual(image2.get(0, 0), image.get(2, 3))
436436
self.assertEqual(image2.get(5, 3), image.get(12, 9))
437437
self.assertEqual(image2.get(1, 2), image.get(1*2+2, 2*2+3))
438438

439439
image2 = tkinter.PhotoImage(master=self.root)
440-
image2.copy_replace(image, from_=(2, 3, 14, 11), subsample=2, zoom=3)
440+
image2.copy_replace(image, from_coords=(2, 3, 14, 11), subsample=2, zoom=3)
441441
self.assertEqual(image2.width(), 18)
442442
self.assertEqual(image2.height(), 12)
443443
self.assertEqual(image2.get(0, 0), image.get(2, 3))

Lib/tkinter/__init__.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,65 +4279,68 @@ def cget(self, option):
42794279
def __getitem__(self, key):
42804280
return self.tk.call(self.name, 'cget', '-' + key)
42814281

4282-
def copy(self, *, from_=None, zoom=None, subsample=None):
4282+
def copy(self, *, from_coords=None, zoom=None, subsample=None):
42834283
"""Return a new PhotoImage with the same image as this widget.
42844284
4285-
The from_ option specifies a rectangular sub-region of the source
4286-
image to be copied. It must be a tuple or a list of 1 to 4 integers
4287-
(x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally opposite
4288-
corners of the rectangle. If x2 and y2 are not specified, the
4289-
default value is the bottom-right corner of the source image. The
4290-
pixels copied will include the left and top edges of the specified
4291-
rectangle but not the bottom or right edges. If the from option is
4292-
not given, the default is the whole source image.
4285+
The FROM_COORDS option specifies a rectangular sub-region of the
4286+
source image to be copied. It must be a tuple or a list of 1 to 4
4287+
integers (x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally
4288+
opposite corners of the rectangle. If x2 and y2 are not specified,
4289+
the default value is the bottom-right corner of the source image.
4290+
The pixels copied will include the left and top edges of the
4291+
specified rectangle but not the bottom or right edges. If the
4292+
FROM_COORDS option is not given, the default is the whole source
4293+
image.
42934294
4294-
If subsample or zoom are specified, the image is transformed as in
4295+
If SUBSAMPLE or ZOOM are specified, the image is transformed as in
42954296
the subsample() or zoom() methods. The value must be a single
42964297
integer or a pair of integers.
42974298
"""
42984299
destImage = PhotoImage(master=self.tk)
4299-
destImage.copy_replace(self, from_=from_, zoom=zoom, subsample=subsample)
4300+
destImage.copy_replace(self, from_coords=from_coords,
4301+
zoom=zoom, subsample=subsample)
43004302
return destImage
43014303

4302-
def zoom(self, x, y='', *, from_=None):
4304+
def zoom(self, x, y='', *, from_coords=None):
43034305
"""Return a new PhotoImage with the same image as this widget
4304-
but zoom it with a factor of x in the X direction and y in the Y
4305-
direction. If y is not given, the default value is the same as x.
4306+
but zoom it with a factor of X in the X direction and Y in the Y
4307+
direction. If Y is not given, the default value is the same as X.
43064308
4307-
The from_ option specifies a rectangular sub-region of the source
4308-
image to be copied, as in the copy() method.
4309+
The FROM_COORDS option specifies a rectangular sub-region of the
4310+
source image to be copied, as in the copy() method.
43094311
"""
43104312
if y=='': y=x
4311-
return self.copy(zoom=(x, y), from_=from_)
4313+
return self.copy(zoom=(x, y), from_coords=from_coords)
43124314

4313-
def subsample(self, x, y='', *, from_=None):
4315+
def subsample(self, x, y='', *, from_coords=None):
43144316
"""Return a new PhotoImage based on the same image as this widget
4315-
but use only every Xth or Yth pixel. If y is not given, the
4316-
default value is the same as x.
4317+
but use only every Xth or Yth pixel. If Y is not given, the
4318+
default value is the same as X.
43174319
4318-
The from_ option specifies a rectangular sub-region of the source
4319-
image to be copied, as in the copy() method.
4320+
The FROM_COORDS option specifies a rectangular sub-region of the
4321+
source image to be copied, as in the copy() method.
43204322
"""
43214323
if y=='': y=x
4322-
return self.copy(subsample=(x, y), from_=from_)
4324+
return self.copy(subsample=(x, y), from_coords=from_coords)
43234325

4324-
def copy_replace(self, sourceImage, *, from_=None, to=None, shrink=False,
4326+
def copy_replace(self, sourceImage, *, from_coords=None, to=None, shrink=False,
43254327
zoom=None, subsample=None, compositingrule=None):
43264328
"""Copy a region from the source image (which must be a PhotoImage) to
43274329
this image, possibly with pixel zooming and/or subsampling. If no
43284330
options are specified, this command copies the whole of the source
43294331
image into this image, starting at coordinates (0, 0).
43304332
4331-
The from_ option specifies a rectangular sub-region of the source
4332-
image to be copied. It must be a tuple or a list of 1 to 4 integers
4333-
(x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally opposite
4334-
corners of the rectangle. If x2 and y2 are not specified, the
4335-
default value is the bottom-right corner of the source image. The
4336-
pixels copied will include the left and top edges of the specified
4337-
rectangle but not the bottom or right edges. If the from option is
4338-
not given, the default is the whole source image.
4333+
The FROM_COORDS option specifies a rectangular sub-region of the
4334+
source image to be copied. It must be a tuple or a list of 1 to 4
4335+
integers (x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally
4336+
opposite corners of the rectangle. If x2 and y2 are not specified,
4337+
the default value is the bottom-right corner of the source image.
4338+
The pixels copied will include the left and top edges of the
4339+
specified rectangle but not the bottom or right edges. If the
4340+
FROM_COORDS option is not given, the default is the whole source
4341+
image.
43394342
4340-
The to option specifies a rectangular sub-region of the destination
4343+
The TO option specifies a rectangular sub-region of the destination
43414344
image to be affected. It must be a tuple or a list of 1 to 4
43424345
integers (x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally
43434346
opposite corners of the rectangle. If x2 and y2 are not specified,
@@ -4346,15 +4349,15 @@ def copy_replace(self, sourceImage, *, from_=None, to=None, shrink=False,
43464349
specified, the source region will be replicated if necessary to fill
43474350
the destination region in a tiled fashion.
43484351
4349-
If shrink is true, the size of the destination image should be
4352+
If SHRINK is true, the size of the destination image should be
43504353
reduced, if necessary, so that the region being copied into is at
43514354
the bottom-right corner of the image.
43524355
4353-
If subsample or zoom are specified, the image is transformed as in
4356+
If SUBSAMPLE or ZOOM are specified, the image is transformed as in
43544357
the subsample() or zoom() methods. The value must be a single
43554358
integer or a pair of integers.
43564359
4357-
The compositingrule option specifies how transparent pixels in the
4360+
The COMPOSITINGRULE option specifies how transparent pixels in the
43584361
source image are combined with the destination image. When a
43594362
compositing rule of 'overlay' is set, the old contents of the
43604363
destination image are visible, as if the source image were printed
@@ -4364,8 +4367,8 @@ def copy_replace(self, sourceImage, *, from_=None, to=None, shrink=False,
43644367
is used as-is. The default compositing rule is 'overlay'.
43654368
"""
43664369
options = []
4367-
if from_ is not None:
4368-
options.extend(('-from', *from_))
4370+
if from_coords is not None:
4371+
options.extend(('-from', *from_coords))
43694372
if to is not None:
43704373
options.extend(('-to', *to))
43714374
if shrink:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Add the :class:`!PhotoImage` method :meth:`!copy_replace` to copy a region
22
from one image to other image, possibly with pixel zooming and/or
3-
subsampling. Add *from_* parameter to :class:`!PhotoImage` methods
3+
subsampling. Add *from_coords* parameter to :class:`!PhotoImage` methods
44
:meth:`!copy()`, :meth:`!zoom()` and :meth:`!subsample()`. Add *zoom* and
55
*subsample* parameters to :class:`!PhotoImage` method :meth:`!copy()`.

0 commit comments

Comments
 (0)