Widget which can display images in PGM, PPM, GIF, PNG format.
| 4279 | |
| 4280 | |
| 4281 | class PhotoImage(Image): |
| 4282 | """Widget which can display images in PGM, PPM, GIF, PNG format.""" |
| 4283 | |
| 4284 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 4285 | """Create an image with NAME. |
| 4286 | |
| 4287 | Valid resource names: data, format, file, gamma, height, palette, |
| 4288 | width.""" |
| 4289 | Image.__init__(self, 'photo', name, cnf, master, **kw) |
| 4290 | |
| 4291 | def blank(self): |
| 4292 | """Display a transparent image.""" |
| 4293 | self.tk.call(self.name, 'blank') |
| 4294 | |
| 4295 | def cget(self, option): |
| 4296 | """Return the value of OPTION.""" |
| 4297 | return self.tk.call(self.name, 'cget', '-' + option) |
| 4298 | # XXX config |
| 4299 | |
| 4300 | def __getitem__(self, key): |
| 4301 | return self.tk.call(self.name, 'cget', '-' + key) |
| 4302 | |
| 4303 | def copy(self, *, from_coords=None, zoom=None, subsample=None): |
| 4304 | """Return a new PhotoImage with the same image as this widget. |
| 4305 | |
| 4306 | The FROM_COORDS option specifies a rectangular sub-region of the |
| 4307 | source image to be copied. It must be a tuple or a list of 1 to 4 |
| 4308 | integers (x1, y1, x2, y2). (x1, y1) and (x2, y2) specify diagonally |
| 4309 | opposite corners of the rectangle. If x2 and y2 are not specified, |
| 4310 | the default value is the bottom-right corner of the source image. |
| 4311 | The pixels copied will include the left and top edges of the |
| 4312 | specified rectangle but not the bottom or right edges. If the |
| 4313 | FROM_COORDS option is not given, the default is the whole source |
| 4314 | image. |
| 4315 | |
| 4316 | If SUBSAMPLE or ZOOM are specified, the image is transformed as in |
| 4317 | the subsample() or zoom() methods. The value must be a single |
| 4318 | integer or a pair of integers. |
| 4319 | """ |
| 4320 | destImage = PhotoImage(master=self.tk) |
| 4321 | destImage.copy_replace(self, from_coords=from_coords, |
| 4322 | zoom=zoom, subsample=subsample) |
| 4323 | return destImage |
| 4324 | |
| 4325 | def zoom(self, x, y='', *, from_coords=None): |
| 4326 | """Return a new PhotoImage with the same image as this widget |
| 4327 | but zoom it with a factor of X in the X direction and Y in the Y |
| 4328 | direction. If Y is not given, the default value is the same as X. |
| 4329 | |
| 4330 | The FROM_COORDS option specifies a rectangular sub-region of the |
| 4331 | source image to be copied, as in the copy() method. |
| 4332 | """ |
| 4333 | if y=='': y=x |
| 4334 | return self.copy(zoom=(x, y), from_coords=from_coords) |
| 4335 | |
| 4336 | def subsample(self, x, y='', *, from_coords=None): |
| 4337 | """Return a new PhotoImage based on the same image as this widget |
| 4338 | but use only every Xth or Yth pixel. If Y is not given, the |