0

I have a problem with python idle not finding my image, I saved it in desktop as 'bg.png'. python displayed it as an error for not finding the problem.

The error found was:

    Traceback (most recent call last):
      File "C:\Users\telta\Desktop\all stuff\stickman game.py", line 233, in    
<module>
    g=Game()
      File "C:\Users\telta\Desktop\all stuff\stickman game.py", line 17, in     __init__
        self.bg = PhotoImage(file="bg.png")
      File "C:\Users\telta\AppData\Local\Programs\Python\Python37-    32\lib\tkinter\__init__.py", line 3545, in __init__
        Image.__init__(self, 'photo', name, cnf, master, **kw)
      File "C:\Users\telta\AppData\Local\Programs\Python\Python37-    32\lib\tkinter\__init__.py", line 3501, in __init__
        self.tk.call(('image', 'create', imgtype, name,) + options)
    _tkinter.TclError: couldn't open "bg.png": no such file or directory
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
hgbc
  • 1
  • 3
  • Saved that images on same directory as script `C:\Users\telta\Desktop\all stuff` – Saleem Ali Oct 09 '19 at 08:36
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 09 '19 at 12:18
  • This is a python and tkinter question, not a python and IDLE question. You would get the same traceback if you run your file directly with Python, from a command line, instead of using IDLE. – Terry Jan Reedy Oct 09 '19 at 20:13

1 Answers1

1

Change

self.bg = PhotoImage(file="bg.png")

To

self.bg = PhotoImage(file="C:\complete-path-to-file\bg.png")

Replace "complete-path-to-file" with the actual path!

ledwinder96
  • 241
  • 5
  • 13
  • Alternatively, place your image in `C:\Users\telta\Desktop\all stuff`, which seems to be where your script is. However, absolute paths are usually better. – clubby789 Oct 09 '19 at 08:44