On Fri, Nov 5, 2010 at 11:53 PM, Patty <[email protected]> wrote:
> 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)
>
Before you convert to an ImageTk, you need to first create a toplevel
window:
import Image
import ImageTk
import Tkinter as tk
root = tk.Tk()
#put your code here
And that should work. You'll still have to add the widgets and what-nots so
you can present your image, but in order to create an image with ImageTk,
you need to have a toplevel window created.
That's what this is telling you
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
HTH,
Wayne
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor