Tkinter PhotoImage Class???
Matthew Dixon Cowles
matt at mondoinfo.com
Fri Oct 5 00:36:44 EDT 2001
On Thu, 4 Oct 2001 23:23:56 +0100, G. Willoughby
<thecalm at NOSPAM.btinternet.com> wrote:
>Has anyone got a piece of code to explain to me how to use the Tkinter
>PhotoImage Class to display a .jpg inside a Tkinter Canvas object?
No. And that's because Tkinter's PhotoImage class doesn't understand
JPEG files. Fredrik Lundh says in his excellent An Introduction to
Tkinter at (wrapped for line length)
http://www.pythonware.com/library/tkinter/
introduction/x6338-options.htm
regarding the PhotoImage class:
The file can contain GIF, PGM (grayscale), or PPM (truecolor)
data. Transparent regions in the GIF file are made transparent. To
handle other file formats, use the corresponding class in the Python
Imaging Library.
And Fredrik's PIL is at
http://www.pythonware.com/downloads/index.htm#pil
and when you have it installed, you can do:
>>> from Tkinter import *
>>> import PIL.ImageTk
>>> r=Tk()
>>> i=PIL.ImageTk.PhotoImage(file="foo.jpg")
>>> c=Canvas(r)
>>> c.pack()
>>> c.create_image(0,0,image=i)
Regards,
Matt
More information about the Python-list
mailing list