Python Forum
Module: Turtle issues
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module: Turtle issues
#1
I am having issues with the module turtle
And i have no idea how to fix it because of the very unspecific error.
My code:
import turtle
win = turtle.Screen()
win.title("Chocolate Clicker (totally not inspired by cookie clicker)")

win.register_shape("choco.gif", shape=(0, 0))

chocolate = turtle.Turtle()
chocolate.shape("choco.gif")

clicks = 0
clicks_gui = turtle.Turtle(); clicks_gui.hideturtle(); clicks_gui.write(clicks)

turtle.mainloop()
Error:
Error:
Traceback (most recent call last): File "/storage/emulated/0/Android/chocolate clicker/main.py", line 8, in <module> chocolate.shape("choco.gif") File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 2778, in shape self._update() File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 2661, in _update self._drawturtle() File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 3008, in _drawturtle shape = self._polytrafo(self._getshapepoly(tshape)) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 2961, in _polytrafo return [(p0+(e1*x+e0*y)/screen.xscale, p1+(-e0*x+e1*y)/screen.yscale) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 2961, in <listcomp> return [(p0+(e1*x+e0*y)/screen.xscale, p1+(-e0*x+e1*y)/screen.yscale) TypeError: cannot unpack non-iterable int object

666+666*666/666-666
Reply
#2
I don't understand what you are doing here:
win.register_shape("choco.gif", shape=(0, 0))
You can call register_shape with a gif filename, and shape = None (defaults to None if not provided) or you can call register_shape with a name and provide a shape. You are doing neither. (0, 0) is not a shape. (0, 0) is a point. [(0, 0)] is a shape.

https://docs.python.org/3/library/turtle...ster_shape

Doing this will create a single point shape named "choco.gif".
win.register_shape("choco.gif", shape=[(0, 0)])
If you want to use a gif file do this instead.
win.register_shape("choco.gif")
Reply
#3
But then it says:
Error:
Traceback (most recent call last): File "/storage/emulated/0/Android/chocolate clicker/main.py", line 5, in <module> win.register_shape("choco.gif", shape=(0, 0)) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 1133, in register_shape shape = Shape("image", self._image(name)) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/turtle.py", line 479, in _image return TK.PhotoImage(file=filename) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/tkinter/__init__.py", line 4071, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/tkinter/__init__.py", line 4016, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "choco.gif"
Reply
#4
It loks like choco.gif is not a gif format file.
Reply
#5
I "converted" to a gif and now it works
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle / turtle question DPaul 2 2,162 Oct-04-2020, 09:23 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020