[Tutor] educational

Peter Otten __peter__ at web.de
Sun Mar 9 11:37:50 CET 2014


Ben Finney wrote:

> Welcome, Michael!
> 
> MICHAEL BASHAGI <myakayebashagi at gmail.com> writes:
> 
>> when i run those codes i get this error message:-
> 
> When showing an error, please show the entire traceback; it usually
> contains information useful for diagnosing the problem.
> 
>> AttributeError: type object 'Image' has no attribute 'open'
> 
> In this case, I'm fairly sure the line producing this error is::
> 
>     image = Image.open("logo.jpg")
> 
> And Python is correct, the ‘Image’ type has no ‘open’ attribute. What
> leads you to think that would work? If there is some article online
> telling you to use that, it's incorrect; please help us to correct that.

There are a few things around called `Image`. The code the OP is trying to 
adapt probably uses the Image from the PIL:

import tkinter
from PIL import ImageTk
from PIL import Image

mGui = tkinter.Tk()

image = Image.open("logo.jpg")
photo = ImageTk.PhotoImage(image=image)

Logo = tkinter.Label(mGui, image=photo)
Logo.grid(row=0, column=3)

mGui.mainloop()

This can be simplified:

import tkinter
from PIL import ImageTk

mGui = tkinter.Tk()
photo = ImageTk.PhotoImage(file="logo.jpg")

Logo = tkinter.Label(mGui, image=photo)
Logo.grid(row=0, column=3)

mGui.mainloop()




More information about the Tutor mailing list