1

I am new in python. so, I tried to show image in my tkinter project. But I continuously received this error. I searched for a lot of codes in Google but everything was out of my league.

###################################################
from tkinter import *

##################################################
StartScreen = Tk()
##Photo Car##
PhotoCarRed = PhotoImage(file="D:\Projects\Python\Practice\1.png")
PlacementPhotoCarRed = Label(StartScreen, image=PhotoCarRed)
PlacementPhotoCarRed.pack(side="top", fill=X)

Here is the error:

enter image description here

1
  • Try using forward slashes instead. Commented Aug 11, 2018 at 19:00

1 Answer 1

1

change

"D:\Projects\Python\Practice\1.png"

into

"D:\\Projects\\Python\\Practice\\1.png"

a single backslash \ acts as a escape character. So you can see in your error that the program reads your paths as "D:\Projects\Python\Practice .png", which is wrong.

Sign up to request clarification or add additional context in comments.

7 Comments

@tazbirul.mbec Glad to be of help! If you feel like your question has been answered, feel free to accept the answer. :)
i tried but stackoverflow is not giving me permission to accept your answer. By the way, your ans worked for png extention but it is not working for jpg
@tazbirul.mbec Do you see the same error, Couldn't open xxxxx.jpg: no such file or directory?
"couldn't recognize data in image file"--> this error is showing
thank you again for your help dear. you are really humble and awesome
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.