Python Forum
Make my colorful name spiral on the screen
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make my colorful name spiral on the screen
#1
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'
Reply
#2
remove the .pen from
t = turtle.pen()
so that it reads
t = turtle
Reply
#3
(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?
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,124 Feb-06-2019, 01:25 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020