Again, Downloading and Displaying an Image from the Internet in Tkinter

Dustan DustanGroups at gmail.com
Mon Jun 5 20:59:57 EDT 2006


Nobody answered last time. I guess they wanted me to give it a shot.
Well, here is how I download the image (it's a class method):

    def download_image(self):
        web_download=self.opener.open(self.url)
        save=open("image.jpg","w")
        save.writelines(web_download.readlines())
        save.close()
        web_download.close()

self.opener is urllib.URLopener(), self.url is the url for the image.

I display the image as follows:

        self.image=t.Label(self.frame,image=path+"\\image.jpg")

t is Tkinter, path is sys.path[0].
(if sys.path[0] is not the proper way of getting the program's path,
inform me; I hunted it down without any reference to look to)


But the image won't display, using any application (including Tkinter,
paint, Firefox, etc.). I'm assuming the reason it can't be read is
because the image is protected from downloading.

So, once again, is there a better way to download and display an image
using Tkinter?

Did I try hard enough for you? Are you going to help me this time?




More information about the Python-list mailing list