You can use turtle.onclick(function, mouse_button)
to execute function when you click your button
.
onclick
needs only function's name without ()
(so called "callback")
on_button_click
has to get two values - mouse position.
import turtle
# --- functions ---
def on_button_click(x, y):
print('button clicked:', x,y)
button.hideturtle()
# --- main ---
screen = turtle.Screen()
button = turtle.Turtle()
button.speed("fastest")
#screen.addshape("icons8-button-100.png") #It's the second button.
#button.shape("icons8-button-100.png") #https://icons8.com/icons/set/button
button.left(90) # The second image is the button I'm using.
button.penup() #It can be resized afer you click download to...
button.goto(0, -120) # 70 x 70 pixels.
button.onclick(on_button_click, 1)
screen.mainloop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…