need hlp-how to read gifs that are on html page

Matt Gushee mgushee at havenrock.com
Thu Dec 30 18:27:24 EST 1999


"Bryan Webb" <bww00 at amdahl.com> writes:

> Hi,
>     I have sampe code to read an html page. I need to be able to read the
> gif files that would be on the html page. ANy help would be appreciated,
> examples even better.

How about something like this?

from Tkinter import *

class VerySimpleImageViewer(Canvas):
	def __init__(self, parent):
		Canvas.__init__(self, parent)
		self.pack()
		self.images = {}
		self.margins = (8, 8)   # or whatever
		self.currentimage = None

	def load(self, url, imgdata):
		## Imgdata is raw GIF data retrieved from the web.
		## VerySimpleImageViewer doesn't know anything about
		## how to get the data.

		## I haven't actually used the 'data' argument -- it's
		## conceivable the graphic might need to be processed
		## somehow before doing this -- but from the docs it
		## looks like you can feed the stuff from directly
		## from the web to PhotoImage.

		imgname = some_unspecified_name_manipulating_function(url)
		self.images[imgname] = PhotoImage(data=imgdata)

	def view(self, imgname):
		if self.currentimage is not None:
			## This doesn't destroy the image, just
			## removes it from the canvas.
			self.delete(self.currentimage)
		x, y = self.margins
		self.currentimage = self.create_image(x, y,
						      self.images[imgname])




Of course, nothing is ever this simple in real life :-)


-- 
Matt Gushee
Portland, Maine, USA
mgushee at havenrock.com
http://www.havenrock.com/



More information about the Python-list mailing list