[Tkinter-discuss] [Tutor] displaying an image

Bryan Oakley bryan.oakley at gmail.com
Fri Oct 5 20:53:30 CEST 2012

On Fri, Oct 5, 2012 at 1:10 PM, Matthew Ngaha <chigga101 at gmail.com> wrote:
> with no solution to my problem after 2 days of pulling my hair out:( i
> realize that some libraries are best for the Python version they
> support the most. Sadly most tkinter users use version 2 unlike me, so
> im pretty much on my own as the solutions don't apply to me. Can
> someone please recommend me a toolkit that is fully supported on
> Python 3 and has a similar or easier learning curve to tkinter? thanks
> for all the help and effort guys.


Sorry for your problems. Tkinter isn't usually so hard for people to
get started with.

Your original message showed you were trying to open a .jpg image. Do
you have the option of converting it to the GIF format? If so, you
don't need PIL at all since .GIF is directly supported by Tkinter.
For example, to display a GIF  image you can do this:

    class ExampleApp(tk.Tk):
        def __init__(self):
            self.image = tk.PhotoImage(file=image_file)
            label = tk.Label(self, image=self.image)

    app = ExampleApp()

The above code works for me just fine with Python 3.2. All you need to
do is define 'image_file' to point to a .gif that you want to display.

Unfortunately Tkinter only directly supports .gif and the older
ppm/pgm formats. For any other format you'll need PIL, or some other
way to convert the image to a supported format.

Yeah, I know it's crazy that Tkinter only supports .GIF. For most
people who use Tkinter there are workarounds. Unfortunately, as a
newbie forced to use Python3, the workaround is not so evident.

More information about the Tkinter-discuss mailing list