Code:
import turtle as trtl
wn = trtl.Screen()
wn.setup(width = 1.0, height = 1.0)
wn.bgpic("Underseav2_BG.png")
wn.mainloop()
Error Message:
Traceback (most recent call last):
File "c:\Users\Natha\Desktop\ATCS Create Task\main_game.py", line 7, in <module>
wn.bgpic("Underseav2_BG.png")
File "C:\Users\Natha\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1482, in bgpic
self._bgpics[picname] = self._image(picname)
File "C:\Users\Natha\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 478, in _image return TK.PhotoImage(file=filename, master=self.cv) File "C:\Users\Natha\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Natha\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
self.tk.call(('image', 'create', imgtype, name,) options)
_tkinter.TclError: couldn't open "Underseav2_BG.png": no such file or directory
This is the Code I wrote and the error message I got. I have the image file in the same folder (shown in this image here:[Code&Folder]
as my code, yet Python says they are not in the same directory. What has happened here, and is there anything I can do to fix it? Thanks!
CodePudding user response:
If you download the image from the Internet, make sure that its original format is png.
If you download the image as a jpg and modify it to png, I think this will not work.