Ich weiß nicht, warum jetzt angezeigt wird, dass kein Bild gefunden werden kann und dass es keine solche Datei oder keinPython

Python-Programme
Anonymous
 Ich weiß nicht, warum jetzt angezeigt wird, dass kein Bild gefunden werden kann und dass es keine solche Datei oder kein

Post by Anonymous »

Ich habe gerade angefangen, Python zu lernen und wollte ein Basisprogramm erstellen, um meine Fähigkeiten zu testen, aber ich habe diesen Fehler gefunden, der vorher nicht aufgetreten ist. Ich weiß nicht, was los ist, es hat bis heute funktioniert.
`

Code: Select all

import turtle

#Window
wn = turtle.Screen()
wn.setup(800, 600)
wn.bgpic("game/sea.gif")
wn.title("TEST")
wn.tracer(0)

#fish.
fish = turtle.Turtle()
turtle.register_shape('game/fish-up.gif')
turtle.register_shape('game/fish-down.gif')
turtle.register_shape('game/fish-left.gif')
turtle.register_shape('game/fish-right.gif')
fish.shape('game/fish-right.gif')
fish.goto(0, 0)
fish.penup()
fish.shapesize(2.5, 2.5)

#Functions
def move_up():
fish.shape('game/fish-up.gif')
y = fish.ycor()
y += 10
fish.sety(y)

def move_down():
fish.shape('game/fish-down.gif')
y = fish.ycor()
y -= 10
fish.sety(y)

def move_left():
fish.shape('game/fish-left.gif')
x = fish.xcor()
x -= 10
fish.setx(x)

def move_right():
fish.shape('game/fish-right.gif')
x = fish.xcor()
x += 10
fish.setx(x)

#Keyboard binding
wn.listen()
wn.onkeypress(move_up, "w")
wn.onkeypress(move_down, "s")
wn.onkeypress(move_left, "a")
wn.onkeypress(move_right, "d")

#Main game loop
while True:
wn.update()

if fish.ycor() > 280:
fish.sety(280)

if fish.ycor() < -280:
fish.sety(-280)

if fish.xcor() > 380:
fish.setx(380)

if fish.xcor() < -380:
fish.setx(-380)

`
In meinem Ordner habe ich vier verschiedene Bilder für den Fisch und eines für den Hintergrund.
Da steht:

Code: Select all

 File "c:\Users\USER\Desktop\PYTHON\game\game.py", line 6, in 
wn.bgpic("game/sea.gif")
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\turtle.py", line 1481, in bgpic
self._bgpics[picname] = self._image(picname)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\turtle.py", line 478, in _image
return TK.PhotoImage(file=filename, master=self.cv)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 4103, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 4048, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "game/sea.gif": no such file or directory
Ich habe versucht, \ anstelle von / zu verwenden und ein anderes Verzeichnis für die Bilder zu verwenden

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post