473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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?

Jun 6 '06 #1
6 3311
I wrote:
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?


I should probably also mention, the only reason I downloaded the image
to a file was because I don't know of any other way to do it. I feel no
need to save the image to my hard drive.

Jun 6 '06 #2
cannot help you with Tkinter but...

save=open("image.jpg","wb")
save.write(web_download.read())
save.close()

perhaps this would let you open the file in Paint

Jun 6 '06 #3
Le Mardi 06 Juin 2006 03:08, Dustan a écrit*:

I should probably also mention, the only reason I downloaded the image
to a file was because I don't know of any other way to do it. I feel no
need to save the image to my hard drive.


using PIL, there is something like this (untested) :

(assuming you have put your image data in a file-like object, ie. a StringIO,
named self._dled_img)

Label(self.frame, image=TkImage(Image.open(self._dled_img)))

--
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
Jun 6 '06 #4
Justin Ezequiel wrote:
cannot help you with Tkinter but...

save=open("image.jpg","wb")
save.write(web_download.read())
save.close()

perhaps this would let you open the file in Paint


Ok, that worked (was it plain w or the writelines/readlines that messed
it up?). But Tkinter still can't find the image. I'm getting an error
message:

TclError: image "C:\Documents and [pathname snipped]" doesn't exist

If it makes a difference, I'm on a Windows XP machine, and don't have
to go cross-platform.

Jun 6 '06 #5
Dustan wrote:
Ok, that worked (was it plain w or the writelines/readlines that messed
it up?).
the plain "w"; very few image files are text files.
But Tkinter still can't find the image. I'm getting an error
message:

TclError: image "C:\Documents and [pathname snipped]" doesn't exist

If it makes a difference, I'm on a Windows XP machine, and don't have
to go cross-platform.


the "image" option takes a PhotoImage object, not a file name:

http://effbot.org/tkinterbook/photoimage.htm

note that the built-in PhotoImage type only supports a few image
formats; to get support for e.g. PNG and JPEG, you can use PIL which
ships with it's own PhotoImage replacement:

http://effbot.org/imagingbook/imagetk.htm

</F>

Jun 6 '06 #6
Fredrik Lundh wrote:
Dustan wrote:
Ok, that worked (was it plain w or the writelines/readlines that messed
it up?).


the plain "w"; very few image files are text files.
> But Tkinter still can't find the image. I'm getting an error
message:

TclError: image "C:\Documents and [pathname snipped]" doesn't exist

If it makes a difference, I'm on a Windows XP machine, and don't have
to go cross-platform.


the "image" option takes a PhotoImage object, not a file name:

http://effbot.org/tkinterbook/photoimage.htm

note that the built-in PhotoImage type only supports a few image
formats; to get support for e.g. PNG and JPEG, you can use PIL which
ships with it's own PhotoImage replacement:

http://effbot.org/imagingbook/imagetk.htm


Thanks for the information.

The reason I hadn't made any attempt before is well illustrated here; I
didn't have enough information at my disposal to know where to start
and how I it works. My references are more basic-level than that (I do
have a better reference to look to, but it's currently inaccessible).

Jun 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: S.W. Rasmussen | last post by:
Handling file downloading with Randy Birch very nice code (http://vbnet.mvps.org/code/internet/ftpdofiledownload.htm) raises a second question: I my case, the user should not be allowed to...
1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
3
by: Brian Kitt | last post by:
I have an animated .gif on my website. It is about 36k. I want this on every page in my site, but it appears that it downloads every time a user loads a page. This will kill dial up users. ...
0
by: Dustan | last post by:
The title pretty much says it all. What is the easiest way in Tkinter to display an image from the internet given the URL?
2
by: sj | last post by:
I am just learning to use Tkinter and am having problems displaying image files. I am able to display an image using tutorials (such as http://www.daniweb.com/code/snippet296.html) But when I try...
9
by: Frank Potter | last post by:
I want to find a multithreaded downloading lib in python, can someone recommend one for me, please? Thanks~
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
1
by: wilson | last post by:
i converted an 8bit rgb .jpg file into .pgm using adobe photoshop and a plugin from http://photoshop.pluginsworld.com/plugins/adobe/362/richard-rosenman/portable-pixmap-importer-exporter.html I...
7
by: hsegoy1979 | last post by:
Dear All Iam using file upload control and i want to display image in another pop up page .But image is not displaying in image control iam sending image path thru querystring . here is my code ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.