A Screenshot of my folder and the script that causes trouble
Hi guys, I want that my program opens the file with the PIL package "settingsicon.png"
and with the usage of the path ./x
but it does not work. It says "No such file or directory: './settingsicon.png'"
I try it with the libary os
but it does not work ether.
import os
from PIL import Image
import customtkinter
# Get absolute file path
file_path = os.path.abspath('path/to/settingsicon.png')
# Load image
img = Image.open(file_path)
Either put the full path or execute it in the directory that has the script and Image. or make it use the script's directory in code like:
script_dir = os.path.dirname(os.path.abspath(__file__))
image_path = os.path.join(script_dir, "settingsicon.png")
settingsicon = customtkinter.CTkImage(dark_image=Image.open(image_path), size=(18, 18))
this should work, based on the code in your screenshot.