[Tutor] Displaying Pictures & Text

Patty patty at cruzio.com
Sat Nov 6 05:53:01 CET 2010


Hi Alan - 

I tried using ImageTk from the PIL library to display jpegs (and hopefully any picture type)  instead of just gif as you suggested below.  I read online that these these types of programs should 
be run from executables not in the interpreter but it crashes and I can't read the error.  Here is the program:

import Image
import ImageTk

fhdl = Image.open("C:\Users\StarShip\PyProgs\SuitGirl.jpg")
ImageTk.PhotoImage(fhdl)

Tested in interpreter and get the following error.  I included Image.show() to be 
sure pic could be displayed and it did come up in HP Photo Viewer just like the gif file did
and I tried the PhotoImage() after I got the cursor back

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> import ImageTk
>>> fhdl = Image.open("C:\Users\StarShip\PyProgs\SuitGirl.jpg")
>>> fhdl.show()
>>> ImageTk.PhotoImage(fhdl)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\PIL\ImageTk.py", line 113, in __init__
    self.__photo = apply(Tkinter.PhotoImage, (), kw)
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 3285, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 3226, in __init__
    raise RuntimeError, 'Too early to create image'
RuntimeError: Too early to create image
>>>

>> 
>
"Alan Gauld" <alan.gauld at btinternet.com> wrote in message news:ib270l$p30$1 at dough.gmane.org...
> 
> "Patty" <patty at cruzio.com> wrote
> 
>> I had a followup question for you all - and would like to know the 
>> answer to Alan's question about print quality - below -
> 
> 
> A Google search led me to this page which seems to offer a solution
> using PIL anmd a module called ImageTk:
> 
> http://codeidol.com/python/python3/A-Tkinter-Tour,-Part-1/Viewing-and-Processing-Images-with-PIL/
> 
> I've never tried it so I'll be interested to hear if it works for 
> you...
> 
> Alan G., 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101105/e82ad061/attachment.html>


More information about the Tutor mailing list