I cannot seem to figure out how to fix a problem with my code regarding import ImageTK
from PIL. I have searched and downloaded Pillow different ways and the error of the code is still the same.
Traceback (most recent call last):
File "8_Age_Calculator_App.py", line 3, in <module>
from PIL import Image, ImageTK
ImportError: cannot import name 'ImageTK'
These are the import codes of the file
import PIL
from PIL import Image, ImageTK
import tkinter as tk
import datetime
and this is the code that is trying to import the image
main_image = Image.open('/Users/Brenden/Documents/Python_OOP/old-people-
running-illo_h.jpg')
main_image.thumbnail((100,100), Image.ANTIALIAS)
main_photo = ImageTK.Photoimage(main_image)
main_label_image = tk.Label(image=main_photo)
main_label.grid(column=1, row=0)
How may I fix this problem?
Use this command for Python 3
sudo apt-get install python3-pil.imagetk
You have a typo in the module you want to import. The k
in ImageTk
should be lower case:
from PIL import Image, ImageTk
this should solve your problem
and in your script you have another case typo, PhotoImage
is CamelCase:
main_photo = ImageTk.PhotoImage(main_image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With