R.H. Tasin
R.H. Tasin

Reputation: 39

Having problem with icon file path in python

Suppose my py file and icons folders are inside 'Project Folder'. Inside the 'icons' folder, there is another folder, the name is 'png'. 'bold-button.png' is inside that 'png' folder.

Now below code is on line number 110:

bold_icon = tk.PhotoImage(file = 'icons/png/bold-button.png')

if I run this code, the terminal shows me the below error. Error Message

What to do, and how to solve it? I have tried a lot, and the path is ok...but it still shows up with this error. even I have tried to open that file with open() but still shows me that path error. what's wrong with my path?

Upvotes: 1

Views: 1345

Answers (1)

acw1668
acw1668

Reputation: 46687

It is because the current directory D:\Python is not the same as the directory (D:\Python\Taditor) where your python script is. So the relative path icons\png\bold-button.png is referring to D:\Python\icons\png\bold-button.png, but not the expected D:\Python\Taditor\icons\png\bold-button.png.

Just change the current directory to D:\Python\Taditor and execute your python script there.

Upvotes: 1

Related Questions