Widget which can display images in PGM, PPM, GIF, PNG format.
| 4402 | |
| 4403 | |
| 4404 | class PhotoImage(Image): |
| 4405 | """Widget which can display images in PGM, PPM, GIF, PNG format.""" |
| 4406 | |
| 4407 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 4408 | """Create an image with NAME. |
| 4409 | |
| 4410 | Valid option names: data, format, file, gamma, height, palette, |
| 4411 | width.""" |
| 4412 | Image.__init__(self, 'photo', name, cnf, master, **kw) |
| 4413 | |
| 4414 | def blank(self): |
| 4415 | """Display a transparent image.""" |
| 4416 | self.tk.call(self.name, 'blank') |
| 4417 | |
| 4418 | def cget(self, option): |
| 4419 | """Return the value of OPTION.""" |
| 4420 | return self.tk.call(self.name, 'cget', '-' + option) |
| 4421 | # XXX config |
| 4422 | |
| 4423 | def __getitem__(self, key): |
| 4424 | return self.tk.call(self.name, 'cget', '-' + key) |
| 4425 | |
| 4426 | def copy(self, *, from_coords=None, zoom=None, subsample=None): |
| 4427 | """Return a new PhotoImage with the same image as this widget. |
| 4428 | |
| 4429 | The FROM_COORDS option specifies a rectangular sub-region of the |
| 4430 | source image to be copied. It must be a tuple or a list of 1 to 4 |
| 4431 | integers (x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally |
| 4432 | opposite corners of the rectangle. If x2 and y2 are not specified, |
| 4433 | the default value is the bottom-right corner of the source image. |
| 4434 | The pixels copied will include the left and top edges of the |
| 4435 | specified rectangle but not the bottom or right edges. If the |
| 4436 | FROM_COORDS option is not given, the default is the whole source |
| 4437 | image. |
| 4438 | |
| 4439 | If SUBSAMPLE or ZOOM are specified, the image is transformed as in |
| 4440 | the subsample() or zoom() methods. The value must be a single |
| 4441 | integer or a pair of integers. |
| 4442 | """ |
| 4443 | destImage = PhotoImage(master=self.tk) |
| 4444 | destImage.copy_replace(self, from_coords=from_coords, |
| 4445 | zoom=zoom, subsample=subsample) |
| 4446 | return destImage |
| 4447 | |
| 4448 | def zoom(self, x, y='', *, from_coords=None): |
| 4449 | """Return a new PhotoImage with the same image as this widget |
| 4450 | but zoom it with a factor of X in the X direction and Y in the Y |
| 4451 | direction. If Y is not given, the default value is the same as X. |
| 4452 | |
| 4453 | The FROM_COORDS option specifies a rectangular sub-region of the |
| 4454 | source image to be copied, as in the copy() method. |
| 4455 | """ |
| 4456 | if y=='': y=x |
| 4457 | return self.copy(zoom=(x, y), from_coords=from_coords) |
| 4458 | |
| 4459 | def subsample(self, x, y='', *, from_coords=None): |
| 4460 | """Return a new PhotoImage based on the same image as this widget |
| 4461 | but use only every Xth or Yth pixel. If Y is not given, the |
no outgoing calls
no test coverage detected
searching dependent graphs…