turtle help

This is the place for queries that don't fit in any of the other categories.

turtle help

Postby Dr_kola » Sat Oct 19, 2013 11:17 am

hi, i want to know if i can and how to press on screed in a specific place and if it press do something like if you press (-100,0,100,300)- x=2
?? can someone help my
Last edited by stranac on Sat Oct 19, 2013 11:27 am, edited 1 time in total.
Reason: First post lock.
Dr_kola
 
Posts: 4
Joined: Sat Oct 19, 2013 11:12 am

Re: turtle help

Postby stranac » Sat Oct 19, 2013 11:29 am

I don't really understand the question.
You can use turtle.onclick() to interact with turtle using the mouse.

If you need more help, post your code and try explaining better what you're having a problem with.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: turtle help

Postby Dr_kola » Sat Oct 19, 2013 11:43 am

i want to do thet you can press on 3 differnt places and each place you press on screen(1of the 3) will do something diffrent if press on the square (-100,0,100,300)(x,x,y,y) you get x= 1 and if the square (-500,0,-300,300) you get x= 2
Dr_kola
 
Posts: 4
Joined: Sat Oct 19, 2013 11:12 am

Re: turtle help

Postby stranac » Sat Oct 19, 2013 11:47 am

Ok, so use turtle.onclick() to get the coordinates and do whatever you want.
I can't know what part you're having trouble with without seeing what you tried, so post some code.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: turtle help

Postby Dr_kola » Sat Oct 19, 2013 11:54 am

how i use turtle.onclick) to go to the coordinats?
Dr_kola
 
Posts: 4
Joined: Sat Oct 19, 2013 11:12 am

Re: turtle help

Postby Dr_kola » Sat Oct 19, 2013 11:57 am

Code: Select all
import turtle

wn=turtle.Screen()
wn.bgcolor('lightblue')
wn.setworldcoordinates(-500,-500,500,500)

bg=turtle.Turtle()
bg.color('black')
bg.width(2)
bg.speed(10)
bg.pu()
bg.goto(-600,0)
bg.pd()
bg.goto(500,0)
bg.pu()
bg.goto(-1000,-1000)

def doorenumber1():
     a=turtle.Turtle()
     a.width(4)
     a.speed(10)
     a.color('black','pink')
     a.pu()
     a.goto(-100,0)
     a.pd()
     a.begin_fill()
     a.goto(100,0)
     a.goto(100,300)
     a.goto(-100,300)
     a.goto(-100,0)
     a.end_fill()
     a.pu()
     a.speed(100)
     a.goto(1000,1000)
     b=turtle.Turtle()
     b.color('black')
     b.pu()
     b.goto(-10,150)
     b.write('2',font=("Arial", 20, "normal"))
     b.speed(100)
     b.goto(1000,1000)

def doorenumber2():
     a=turtle.Turtle()
     a.width(4)
     a.speed(10)
     a.color('black','pink')
     a.pu()
     a.goto(-500,0)
     a.pd()
     a.begin_fill()
     a.goto(-300,0)
     a.goto(-300,300)
     a.goto(-500,300)
     a.goto(-500,0)
     a.end_fill()
     a.pu()
     a.speed(100)
     a.goto(1000,1000)
     b=turtle.Turtle()
     b.color('black')
     b.pu()
     b.goto(-410,150)
     b.write('1',font=("Arial", 20, "normal"))
     b.speed(100)
     b.goto(1000,1000)

def doorenumber3():
     a=turtle.Turtle()
     a.width(4)
     a.speed(10)
     a.color('black','pink')
     a.pu()
     a.goto(500,0)
     a.pd()
     a.begin_fill()
     a.goto(300,0)
     a.goto(300,300)
     a.goto(500,300)
     a.goto(500,0)
     a.end_fill()
     a.pu()
     a.speed(100)
     a.goto(1000,1000)
     b=turtle.Turtle()
     b.color('black')
     b.pu()
     b.goto(390,150)
     b.write('3',font=("Arial", 20, "normal"))
     b.speed(100)
     b.goto(1000,1000)]



i want thet x=1 if you click on first x=2 if you click on the sec an 3 of the tird
Dr_kola
 
Posts: 4
Joined: Sat Oct 19, 2013 11:12 am

Re: turtle help

Postby stranac » Sat Oct 19, 2013 12:05 pm

If you read the documentation I linked to, you'll see that turtle.onclick() takes a function as its first argument.
This function will receive the coordinates that were clicked as arguments.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: metulburr and 6 guests