Python Forum
Make my colorful name spiral on the screen - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Make my colorful name spiral on the screen (/thread-4142.html)



Make my colorful name spiral on the screen - RedSkeleton007 - Jul-26-2017

my question here
In my book, "Teach Your Kids To Code" by Bryson Payne, I'm trying some sample code in the book that's supposed to ask the user to input his/her name and make it spiral on the screen in 4 different colors. I would paste a sample picture of what it's supposed to look like, but every time I try to insert an image into this post, it just says that an unknown error occurs.

For those of you are good enough to not need the image, here is my code:
#SpiralMyName.py - prints a colorful spiral of the user's name

import turtle
t = turtle.pen()
turtle.bgcolor("black")
colors = ["red", "yellow", "blue", "green"]

#ask the user's name using turtle's textinput pop-up window
yourName = turtle.textinput("Enter your name", "What is your name?")

#draw a spiral of the name on the screen written 100 times:
for x in range(100):
    t.pencolor(colors[x%4])#rotate through the four colors
    t.penup()#don't draw the regular spiral lines
    t.forward(x*4)#just move the turtle on the screen
    t.pendown()#write the inputted name, bigger each time
    t.write(yourName, font = ("Arial", int( (x + 4) / 4), "bold"))
    t.left(92)#turn left, just as in our other spirals
And the error (NOT the unknown image error, but the error from my code in Python Shell) is:
Traceback (most recent call last):
  File "D:/Python/Python36-32/SamsPrograms/SpiralMyName.py", line 13, in <module>
    t.pencolor(colors[x%4])#rotate through the four colors
AttributeError: 'dict' object has no attribute 'pencolor'



RE: Make my colorful name spiral on the screen - Larz60+ - Jul-26-2017

remove the .pen from
t = turtle.pen()
so that it reads
t = turtle



RE: Make my colorful name spiral on the screen - RedSkeleton007 - Jul-26-2017

(Jul-26-2017, 02:15 AM)Larz60+ Wrote: remove the .pen from
t = turtle.pen()
so that it reads
t = turtle

You were right on the money Larz60! Thank you. Do you also know how to upload and insert images in posts?


RE: Make my colorful name spiral on the screen - Larz60+ - Jul-26-2017

see: https://python-forum.io/misc.php?action=help&hid=35

Apparently the upload image is out of order. A new editor was installed a few hours ago, and that option isn't available at the moment,
or has moved.