Ich versuche ein Python-Malprogramm zu erstellen, wo Sie mit Turtle malen können. Alles läuft reibungslos und das endgültige Design war großartig. Ich möchte, dass die Schildkrötenform statt eines Pfeils ein Stift ist, also habe ich eine einfache .gif-Datei erstellt und die Form registriert und dann die Schildkröte zur Form gebracht. Wenn ich es laufen sie sagt dies:Python Turtle Shape "pyimage1"
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 "/Users/h205p6/PycharmProjects/Turtle Projects/python paint.py"
Traceback (most recent call last):
File "/Users/h205p6/PycharmProjects/Turtle Projects/python paint.py", line 124, in <module>
turtle.shape(pencil)
File "<string>", line 8, in shape
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py", line 2681, in shape
self.turtle._setshape(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py", line 2410, in _setshape
self._item = screen._createimage(screen._shapes["blank"]._data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py", line 729, in _createimage
return self.cv.create_image(0, 0, image=image)
File "<string>", line 1, in create_image
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2314, in create_image
return self._create('image', args, kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2305, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
Process finished with exit code 1
Ich weiß nicht, warum es dies überhaupt tut. Ich habe versucht und versucht, es zu bekommen zu arbeiten, aber ich kann es einfach nicht herausfinden
Hier ist mein Code:
import turtle
import Tkinter
root = Tkinter.Tk()
tb = 6
ts = 1
def cs():
turtle.pendown()
turtle.circle(25)
turtle.penup()
def cb():
turtle.pendown()
turtle.circle(50)
turtle.penup()
def square():
turtle.pendown()
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.penup()
def triangle():
turtle.pendown()
turtle.forward(50)
turtle.left(120)
turtle.forward(50)
turtle.left(120)
turtle.forward(50)
turtle.left(120)
turtle.penup()
def green():
turtle.color("green")
def red():
turtle.color("red")
def blue():
turtle.color("blue")
def yellow():
turtle.color("yellow")
def reset():
turtle.color("black")
def white():
turtle.color("white")
def orange():
turtle.color("orange")
def big():
turtle.pensize(tb)
def small():
turtle.pensize(ts)
def clear():
turtle.clear()
def saveImg():
turtle.hideturtle()
name = raw_input('What would you like to name your drawing?: ')
tg = turtle.getscreen().getcanvas()
tg.postscript(file = name + ".eps")
print "You can find your .eps file in the finder/directory and open it to convert it to .pdf"
print "Or, follow this link to convert it to a .png file!"
print "http://image.online-convert.com/convert-to-png"
exit()
greenb = Tkinter.Button(root, text="green", fg ="green", command=green)
redb = Tkinter.Button(root, text="red", fg ="red", command=red)
blueb = Tkinter.Button(root, text="blue", fg ="blue", command=blue)
yellowb = Tkinter.Button(root, text="yellow", fg ="yellow", command=yellow)
black = Tkinter.Button(root, text="black", command=reset)
white = Tkinter.Button(root, text="white", command=white)
orangeb = Tkinter.Button(root, text="orange", fg ="orange", command=orange)
bigger = Tkinter.Button(root, text="big pensize", command=big)
smaller = Tkinter.Button(root, text="reset pensize", command=small)
clear = Tkinter.Button(root, text="clear", command=clear)
square = Tkinter.Button(root, text="create square", command=square)
triangle = Tkinter.Button(root, text="create triangle", command=triangle)
cb = Tkinter.Button(root, text="make big circle", command=cb)
cs = Tkinter.Button(root, text="make small circle", command=cs)
saveImgb = Tkinter.Button(root, text="save drawing", command=saveImg)
def gothere(event):
turtle.penup()
turtle.goto(event.x-360,340-event.y)
turtle.pendown()
def movearound(event):
turtle.goto(event.x-360,340-event.y)
def release(event):
turtle.penup()
def reset(event):
turtle.clear()
turtle.reset()
turtle.speed(0)
c=turtle.getcanvas()
c.bind("<Button-1>", gothere)
c.bind("<B1-Motion>", movearound)
c.bind("<ButtonRelease-1>", release)
c.bind("<Escape>",reset)
redb.pack()
orangeb.pack()
yellowb.pack()
greenb.pack()
blueb.pack()
white.pack()
black.pack()
bigger.pack()
smaller.pack()
cb.pack()
cs.pack()
triangle.pack()
square.pack()
clear.pack()
saveImgb.pack()
pencil = "/Users/h205p6/Desktop/ok.gif"
turtle.register_shape(pencil)
turtle.shape(pencil)
turtle.resizemode("auto")
s=turtle.Screen()
turtle.title("Python Paint")
root.title("Paint Tablet")
s.listen()
s.bgcolor("white")
turtle.mainloop()
root.mainloop()
Bitte helfen Sie mir! Ich möchte wirklich, dass das funktioniert! Sei nicht gemein! Denken Sie daran, Ihre Älteren zu respektieren. HackingYourNan heraus.
Ich glaube nicht, dass Sie all diesen Code benötigen, um dieses Problem zu veranschaulichen. Vielleicht möchten Sie http://www.stackoverflow.com/help/mcve lesen. –