7 Replies - 1957 Views - Last Post: 30 April 2013 - 02:58 PM Rate Topic: ***** 1 Votes

#1 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

turtle is not defined?

Posted 30 April 2013 - 11:48 AM

Hello,

i am working currently on a project for my class (python 3.2.3) and when i run the program it says that the turtle is not defined?

from turtle import *

turtle_1 = Turtle()
turtle_2 = Turtle()
turtle_3 = Turtle()

def callback_1(x, y):
    color("red")
    shape("circle")
    circle("100")

def callback_2(x, y):
    color("blue")
    shape("square")
    circle("100")

def callback_3(x, y):
    color("green")
    shape("triangle")
    circle("100")

def place_turtles():
    turtle_1.color("red")
    turtle_1.shape("circle")
    turtle_1.penup()
    turtle_1.goto(-200, -200)
    turtle_2.color("blue")
    turtle_2.shape("square")
    turtle_2.penup()
    turtle_2.goto(0, -200)
    turtle_3.color("blue")
    turtle_3.shape("square")
    turtle_3.penup()
    turtle_3.goto(200, -200)

def start_over():
    resetscreen()
    place_turtles()

listen()
onkey(start_over, "space")

ondrag(goto)
place_turtles()
screen=getscreen()
screen.onclick(callback_1)
screen.turtle_1.onclick(callback_1)
screen.turtle_2.onclick(callback_2)
screen.turtle_3.onclick(callback_3)
mainloop()



what i dont get: i dont see why it says the turtle_1 = Turtle() is not defined

Is This A Good Question/Topic? 1
  • +

Replies To: turtle is not defined?

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8001
  • View blog
  • Posts: 13,707
  • Joined: 19-March 11

Re: turtle is not defined?

Posted 30 April 2013 - 11:53 AM

is python-tk installed?
Was This Post Helpful? 0
  • +
  • -

#3 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: turtle is not defined?

Posted 30 April 2013 - 11:54 AM

View Postjon.kiparsky, on 30 April 2013 - 11:53 AM, said:

is python-tk installed?

python-tk?
-edit i got it to work but i dont understand this error:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\Python32\lib\turtle.py", line 675, in eventfun
fun(x, y)
File "C:\Python32\test.py", line 20, in callback_3
circle("100")
File "<string>", line 1, in circle
File "C:\Python32\lib\turtle.py", line 1969, in circle
steps = 1+int(min(11+abs(radius)/6.0, 59.0)*frac)
TypeError: bad operand type for abs(): 'str

This post has been edited by snow_ninja67: 30 April 2013 - 11:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8001
  • View blog
  • Posts: 13,707
  • Joined: 19-March 11

Re: turtle is not defined?

Posted 30 April 2013 - 12:01 PM

Turtle is part of the python-tk package, if I'm not mistaken.

If you type "import turtle" at the interpreter prompt, what do you get?

EDIT:

Okay, you got that.

Looks to me like you're passing a string instead of a number to some turtle function. Make sure that if you get user input, you convert it to numeric values. If you get input, and I type '144', you're going to get the string "123" and not the number 144 (That is, you're going to get the characters '1', '4', '4', not the number which is the square of 12)

This post has been edited by jon.kiparsky: 30 April 2013 - 12:05 PM

Was This Post Helpful? 0
  • +
  • -

#5 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: turtle is not defined?

Posted 30 April 2013 - 12:03 PM

View Postjon.kiparsky, on 30 April 2013 - 12:01 PM, said:

Turtle is part of the python-tk package, if I'm not mistaken.

If you type "import turtle" at the interpreter prompt, what do you get?

i just get >>>
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8001
  • View blog
  • Posts: 13,707
  • Joined: 19-March 11

Re: turtle is not defined?

Posted 30 April 2013 - 12:06 PM

View Postsnow_ninja67, on 30 April 2013 - 02:03 PM, said:

View Postjon.kiparsky, on 30 April 2013 - 12:01 PM, said:

Turtle is part of the python-tk package, if I'm not mistaken.

If you type "import turtle" at the interpreter prompt, what do you get?

i just get >>>



Good. This is the unix way: succeed quietly, fail loudly. If you get no response, it means that it didn't return an error.
Was This Post Helpful? 0
  • +
  • -

#7 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: turtle is not defined?

Posted 30 April 2013 - 02:02 PM

View Postjon.kiparsky, on 30 April 2013 - 12:01 PM, said:

Turtle is part of the python-tk package, if I'm not mistaken.

If you type "import turtle" at the interpreter prompt, what do you get?

EDIT:

Okay, you got that.

Looks to me like you're passing a string instead of a number to some turtle function. Make sure that if you get user input, you convert it to numeric values. If you get input, and I type '144', you're going to get the string "123" and not the number 144 (That is, you're going to get the characters '1', '4', '4', not the number which is the square of 12)

I have not yet learnt how to do that can you please explain it to me is it similar to callback_1 = (input("please input something"))
Was This Post Helpful? 0
  • +
  • -

#8 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: turtle is not defined?

Posted 30 April 2013 - 02:58 PM

[quote name='snow_ninja67' date='30 April 2013 - 02:02 PM' timestamp='1367355735' post='1844567']

View Postjon.kiparsky, on 30 April 2013 - 12:01 PM, said:

Turtle is part of the python-tk package, if I'm not mistaken.

If you type "import turtle" at the interpreter prompt, what do you get?

EDIT:

Okay, you got that.

Looks to me like you're passing a string instead of a number to some turtle function. Make sure that if you get user input, you convert it to numeric values. If you get input, and I type '144', you're going to get the string "123" and not the number 144 (That is, you're going to get the characters '1', '4', '4', not the number which is the square of 12)

edit
i have fixed that issue (derp on ym side rolf buuuut it dose not fully do what it is intended to do take example if i were to click on the blue square it dose not let me draw in blue here is my current code:
from turtle import *

turtle_1 = Turtle()
turtle_2 = Turtle()
turtle_3 = Turtle()
def callback_1(x, y):
    color("red")
    shape("circle")
    circle(100)

def callback_2(x, y):
    color("blue")
    shape("square")
    circle(100)

def callback_3(x, y):
    color("green")
    shape("triangle")
    circle(100)

def place_turtles():
    turtle_1.color("red")
    turtle_1.shape("circle")
    turtle_1.penup()
    turtle_1.goto(-200, -200)
    turtle_2.color("blue")
    turtle_2.shape("square")
    turtle_2.penup()
    turtle_2.goto(0, -200)
    turtle_3.color("green")
    turtle_3.shape("triangle")
    turtle_3.penup()
    turtle_3.goto(200, -200)

def start_over():
    resetscreen()
    place_turtles()

listen()
onkey(start_over, "space")
ondrag(goto)
place_turtles()
screen=getscreen()
screen.onclick(callback_1)
turtle_1.onclick(callback_1)
turtle_2.onclick(callback_2)
turtle_3.onclick(callback_3)
mainloop()




This post has been edited by snow_ninja67: 30 April 2013 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1