[Tutor] Turtle color question

Peter Otten __peter__ at web.de
Thu Mar 29 15:51:26 EDT 2018


Roger Lea Scherer wrote:

> I've tried everything I can think of but cannot get the pencolor to
> change. (Although the arrow drawing the boxes changes color.) I've placed
> it in places I didn't even think it would work. The arrow draws what looks
> like the boxes I expect, but the color looks the same as the background.
> So I assigned a variable and printed that variable which says None. See:
> 
>  RESTART: C:/Users/Roger/AppData/Local/Programs/Python/Python36/turtle
> square draw.py
> None
>>>>
> 
> Removing " color = " doesn't change the outcome. I hope this adequately
> explains things.Thanks, again.
> 
> ​import turtle
> 
> def drawSquare(t, sz):
>     """Get turtle t to draw a square of sz side"""
>     t.pu()

I recommend that you use the long name here, penup() instead of pu().
I should then become glaringly obvious that you lift the pen but never put 
it down again...

>     t.forward(sz*2)
> 
>     for i in range(4):
>         t.forward(sz)
>         t.left(90)
> 
> 
> wn = turtle.Screen()
> wn.bgcolor("blue")
> 
> alex = turtle.Turtle()
> color = alex.pencolor("darkgreen")
> print(color)
> 
> def main():
>     for i in range(4):
>         drawSquare(alex,20)
> 
> main()
> 
> wn.exitonclick()
>> 




More information about the Tutor mailing list