[Python] How to make this wheel spin?

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have created the wheel, but when I try to make code to spin it will not work.

    I have already tried to make it using a loop but that was near impossible for me. I am basically drawing the wheel over. Here is some code from the spinning wheel part:

    turtle.listen()
    if turtle.onkeypress("space"):
    colors = ['#880000','#884400','#884400','#888800',
    '#888800','#008800','#008800','#008800',
    '#008800','#008800','#008888','#008888',
    '#008888','#008888','#008888','#000088',
    '#000088','#000088','#000088','#000088']

    for color in colors:
    slice_angle = 360 / len(colors)
    heading, position = 90, (center[0] + radius, center[1])
    turtle.color(color, color)
    turtle.speed(0)
    turtle.penup()
    turtle.goto(position)
    turtle.setheading(heading)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(radius, extent=slice_angle)
    heading, position = turtle.heading(), turtle.position()
    turtle.penup()
    turtle.goto(center)
    turtle.end_fill()
    turtle.penup()

    time.sleep(0.2)
    colors = ['#884400','#884400','#888800',
    '#888800','#008800','#008800','#008800',
    '#008800','#008800','#008888','#008888',
    '#008888','#008888','#008888','#000088',
    '#000088','#000088','#000088','#000088','#880000']
    for color in colors:
    slice_angle = 360 / len(colors)
    heading, position = 90, (center[0] + radius, center[1])
    turtle.color(color, color)
    turtle.speed(0)
    turtle.penup()
    turtle.goto(position)
    turtle.setheading(heading)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(radius, extent=slice_angle)
    heading, position = turtle.heading(), turtle.position()
    turtle.penup()
    turtle.goto(center)
    turtle.end_fill()
    turtle.penup()

    time.sleep(0.2)


    The code keeps on going to make the wheel 'spin'.

    This is what I get:

    Exception in Tkinter callback
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 701, in eventfun
    fun()
    TypeError: 'str' object is not callable

    Continue reading...

Compartilhe esta Página