Reputation: 570
I am trying to insert a photo in tkinter window python. I am using the library PIL (pillow) but it gives my an error
code:
from PIL import ImageTk, Image
my_img = ImageTk.PhotoImage(Image.open(link))
my_label = Label(window, image=my_img)
my_label.place(x=x,y=y)
Error:
Traceback (most recent call last):
File "C:\Users\LitterHelper\main.py", line 86, in <module>
i._img(window, 50, 150, "C:\\img\\Fries.gif")
File "C:\Users\LitterHelper\main.py", line 5, in _img
my_img = ImageTk.PhotoImage(Image.open(f))
^^^^^^^^^^
AttributeError: type object 'Image' has no attribute 'open'
I want the image to open in the tkinter window
Upvotes: 0
Views: 69
Reputation: 16184
Something else in your code is overwriting Image
with the Image
class inside the Image
module. The result of doing:
from PIL import Image
print(type(Image))
should result in module
being printed. I get your error if after doing the above import
I do:
Image.Image.open('foo.bar')
which prints your error:
AttributeError: type object 'Image' has no attribute 'open'
Somewhere else in your code you might be doing:
from PIL.Image import Image
or maybe you're assigning something to Image
.
Upvotes: 1