Reputation:
I'm a beginner to Python programming (and programming in general) and was just playing around with the Turtle module in Python and was wondering why the coordinates of the turtle using turtle.pos() in the below program always gives (0, 0) after moving the turtle, when displayed in the graphical interface? This isn't the case when using the Python shell to move the turtle with the same turtle.forward()?
import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
def draw_lines(w, height):
w.begin_fill()
w.right(90)
w.forward(height)
w.write(turtle.pos())
line = turtle.Turtle()
line.color("blue", "red")
line.pensize(3)
height = [50]
for x in height:
draw_lines(line, x)
wn.mainloop()
Thank you!
Upvotes: 1
Views: 910
Reputation: 7588
Your turtle is passed as an argument (w) to draw_lines:
Correct draw_lines, it is easier if you use better names in your arguments:
def draw_lines(my_turtle, height):
my_turtle.begin_fill()
my_turtle.right(90)
my_turtle.forward(height)
my_turtle.write(my_turtle.pos())
Upvotes: 0