CustomTkinter
CustomTkinter copied to clipboard
CTkImage ImportError: PIL.Image and PIL.ImageTk couldn't be imported
I'm trying to put an image on a label, and saw this warning:
CTkLabel Warning: Given image is not CTkImage but <class 'tkinter.PhotoImage'>. Image can not be scaled on HighDPI displays, use CTkImage instead.
So I switched to a CTkImage but now I'm getting this error:
Traceback (most recent call last):
File "/home/james/file_explorer/.env/lib/python3.10/site-packages/customtkinter/windows/widgets/image/ctk_image.py", line 41, in _check_pil_import
_, _ = Image, ImageTk
NameError: name 'Image' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/james/file_explorer/gui_main.py", line 40, in <module>
f1 = File1("test1", tk, 0)
File "/home/james/file_explorer/gui_main.py", line 10, in __init__
self.icon = CTkImage("file.png").subsample(10)
File "/home/james/file_explorer/.env/lib/python3.10/site-packages/customtkinter/windows/widgets/image/ctk_image.py", line 27, in __init__
self._check_pil_import()
File "/home/james/file_explorer/.env/lib/python3.10/site-packages/customtkinter/windows/widgets/image/ctk_image.py", line 43, in _check_pil_import
raise ImportError("PIL.Image and PIL.ImageTk couldn't be imported")
ImportError: PIL.Image and PIL.ImageTk couldn't be imported
Everything worked file using tkinter's PhotoImage, and I have PIL installed.
Try this format:
my_image = customtkinter.CTkImage(light_image=Image.open("<path to light mode image>"), dark_image=Image.open("<path to dark mode image>"), size=(30, 30))
It doesn't throw an error, but it does stretch the image which I can't seem to do anything about.
Yeah I didn't see the new patch update my bad, I updated the code now it should be working fine. Try it.
from PIL import Image, ImageTk has to work, then everything should be fine.