Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add a image into PyCharm on Mac

I am trying to use tkinter to make a GUI and everything works for me except getting an image to import. The error is this


  • Error Message

self.tk.call((‘image’, ‘create’, imgtype, name,) + options)
_tkinter.TclError: couldn’t open "MainDisk/Users/Matt/PythonProjects/Car_image.jpg": no such file or directory

  • My line of code

photo = tk.PhotoImage(file="MainDisk/Users/Matt/PythonProjects/Car_image.jpg")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


Is this the way that you would import an image on Mac? Sorry I am very confused and just am not sure how to get this to work. The image is in the right place but I have to be doing something wrong clearly. Me and someone else had this working on a windows computer but can’t get it to work on Mac. Help is appreciated.


>Solution :

You can try :

photo = tk.PhotoImage(r"MainDisk/Users/Matt/PythonProjects/Car_image.jpg")

The Reason for your error was that your image path contained backslash \ in it. As we know backslashes \ are treated as escape characters by the compiler, and therefore interprets any character following a \ as a escape sequence, which is not our intention here. So, In order to get through this problem provide raw path of your image file, by using r before the image path string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading