On click functions with turtle?

B

baujacob

Hi everyone, I have this program that writes out the name "John" in block letters. I was just messing around because we were just introduced to turtlea few weeks ago in class and I'm just getting the hang of it. Before I wasusing "goto" a certain angle, but now I'm using "seth" and it's so much easier.

Here is my question:

I want to click on a certain letter ("J" or "O" or "H" or "N") and have theturtle hover above that letter as in when the turtle is above the letter "N" at the end of my program. Do I need to set the letters up as objects so when I click inside them, I can set the turtles x and y coordinate to hoverabove that letter?

Or do I need to define each letter as a function and make some "if" statements like "if user clicks inside letter (J,O,H, or N), go to specific x, y coordinate?"

Thanks for any help in advance. Drawing is frustrating with python, but I'mstarting to understand how it works. I think it's just the angles that trip me up.

Here is my code:

import turtle
rectangle = turtle.Turtle()

def makeRec():
rectangle.shape("turtle")
rectangle.pensize(2)
rectangle.pencolor("red")
rectangle.speed(5)

#Draws the letter O
rectangle.penup()
rectangle.seth(180)
rectangle.fd(50)
rectangle.seth(90)
rectangle.pendown()
rectangle.pencolor("black")
rectangle.circle(30)
rectangle.penup()
rectangle.seth(180)
rectangle.fd(10)
rectangle.seth(90)
rectangle.pendown()
rectangle.circle(20)

rectangle.penup()
rectangle.seth(180)
rectangle.fd(70)
rectangle.seth(90)
rectangle.fd(30)
rectangle.seth(-90)

#Draws the letter J
rectangle.pendown()
rectangle.fd(40)
rectangle.circle(-20,180)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(-90)
rectangle.circle(10,180)
rectangle.fd(40)
rectangle.seth(0)
rectangle.fd(10)

#Draws the letter H
rectangle.penup()
rectangle.fd(100)
rectangle.seth(-90)
rectangle.pendown()
rectangle.fd(60)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(90)
rectangle.fd(20)
rectangle.seth(0)
rectangle.fd(20)
rectangle.seth(-90)
rectangle.fd(20)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(90)
rectangle.fd(60)
rectangle.seth(180)
rectangle.fd(10)
rectangle.seth(-90)
rectangle.fd(30)
rectangle.seth(180)
rectangle.fd(20)
rectangle.seth(90)
rectangle.fd(30)
rectangle.seth(180)
rectangle.fd(10)

#Draws the letter N
rectangle.penup()
rectangle.seth(0)
rectangle.fd(60)
rectangle.seth(-90)
rectangle.fd(60)
rectangle.seth(90)
rectangle.pendown()
rectangle.fd(60)
rectangle.seth(0)
rectangle.fd(10)
rectangle.seth(-60)
rectangle.fd(50)
rectangle.seth(90)
rectangle.fd(45)
rectangle.seth(0)
rectangle.fd(13)
rectangle.seth(-90)
rectangle.fd(65)
rectangle.seth(180)
rectangle.fd(15)
rectangle.seth(120)
rectangle.fd(40)
rectangle.seth(-90)
rectangle.fd(35)
rectangle.seth(180)
rectangle.fd(13)
rectangle.seth(90)
rectangle.fd(5)

#Sets the turtle to the position above letter N
rectangle.penup()
rectangle.seth(90)
rectangle.fd(100)
rectangle.seth(180)
rectangle.fd(80)
rectangle.seth(-90)
print(rectangle.pos())
rectangle.setx(54)
rectangle.sety(70)
makeRec()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top