It just so happens that I've a four inner planet simulator left over from answering another SO question that we can plug onclick()
methods into to see how well this works with moving turtles:
""" Simulate motion of Mercury, Venus, Earth, and Mars """
from turtle import Turtle, Screen
planets = {
'mercury': {'diameter': 0.383, 'orbit': 58, 'speed': 7.5, 'color': 'gray'},
'venus': {'diameter': 0.949, 'orbit': 108, 'speed': 3, 'color': 'yellow'},
'earth': {'diameter': 1.0, 'orbit': 150, 'speed': 2, 'color': 'blue'},
'mars': {'diameter': 0.532, 'orbit': 228, 'speed': 1, 'color': 'red'},
}
def setup_planets(planets):
for planet in planets:
dictionary = planets[planet]
turtle = Turtle(shape='circle')
turtle.speed("fastest") # speed controlled elsewhere, disable here
turtle.shapesize(dictionary['diameter'])
turtle.color(dictionary['color'])
turtle.penup()
turtle.sety(-dictionary['orbit'])
turtle.pendown()
dictionary['turtle'] = turtle
turtle.onclick(lambda x, y, p=planet: on_click(p))
revolve()
def on_click(planet):
p = screen.textinput("Guess the Planet", "Which planet is this?")
if p and planet == p:
pass # do something interesting
def revolve():
for planet in planets:
dictionary = planets[planet]
dictionary['turtle'].circle(dictionary['orbit'], dictionary['speed'])
screen.ontimer(revolve, 50)
screen = Screen()
setup_planets(planets)
screen.mainloop()
Generally, it works fine. Sometimes the planets stop in their orbits while the textinput()
dialog panel is visible, other times they don't. I'll leave this issue for the OP to resolve, as needed.
