0

I am not so new to Python that this is going to be a syntax error. I have never actually messed with turtle graphics that much though, so this was totally new to me. Anyway I was trying to make a turtle graphic spiral that would take input from a user(strings, numbers etc.) and turn it into a neat spiral. anyway I got this error message when ran I the code.

Please note I am using Python 3.

Traceback (most recent call last):
  File "spiral_my_name.py", line 6, in <module>
    your_name = turtle.textinput("Enter your name", "What is your mame?") 
AttributeError: 'module' object has no attribute 'textinput'

that was the error message I got from this syntax:

import turtle
t = turtle.Pen()
turtle.bgcolor('black')
colors = ['purple', 'pink', 'green', 'blue'] 

your_name = turtle.textinput("Enter your name", "What is your name?") 
for x in range(100):
    t.pencolor(colors[x%4])
    t.penup()
    t.forward(x*4)
    t.pendown()
    t.write(your_name, font = ("Arial", int ( (x+4) / 4), "bold") )
    t.left(92)

Now I don't personally use Python for this a whole lot, so I was just going to let this go, but this is an Attribute error. I sort of want to know why this is happening.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Possible duplicate of [AttributeError: 'module' object has no attribute 'textinput'](https://stackoverflow.com/questions/41674910/attributeerror-module-object-has-no-attribute-textinput) – Pyromonk Jan 05 '18 at 04:53
  • Yes except he was using "python 2" I am using "Python 3." – Sherman B. Jan 05 '18 at 05:24
  • Is that what you think or does `print(sys.version)` return a version number greater than 3? – Pyromonk Jan 05 '18 at 05:26
  • Indeed it does. My version is "Python3.4.2" – Sherman B. Jan 05 '18 at 05:29
  • Can you please take a look at the following links? [#0](https://www.reddit.com/r/learnpython/comments/465sej/my_turtles_commands_arent_working/), [#1](https://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute). Otherwise I'm out of ideas. – Pyromonk Jan 05 '18 at 05:35
  • 1
    well i apreciate your help, but it did not change a thing. I probably made a stupid error somewhere. I will keep looking. Thanks Again! God bless! – Sherman B. Jan 05 '18 at 05:43
  • This looks similar to the error you get when you mistakenly name your own source file turtle.py – cdlane Apr 02 '20 at 03:38

2 Answers2

0

Well, for the last hour i've been trying to figure this out. I found the book you took this code from. At first i tried running it with repl (a web where you can run the program online) and it didn't work, but when i run it on the cmd it did actually work, as well as in the IDLE (the running environment shown in the book). Where are you running your code?

Or251
  • 196
  • 10
  • hey thanks for getting back to me. Yea I actually skipped that part of the book and was just getting back to it now, lol, anyway I have been running the code on my raspberry pi, simply because that is the main thing i have been working on lately. (for a school project) will the code need to change in the raspberry pi. – Sherman B. Jan 07 '18 at 00:12
0

You have to replace this:

your_name = turtle.textinput("Enter your name", "What is your name?")

With:

your_name = turtle.Screen().textinput("Enter your name", "What is your name?")
Azametzin
  • 5,223
  • 12
  • 28
  • 46
Arjun S
  • 40
  • 5
  • Adding some more details like why you should use the `Screen()` would be helpful in understanding the solution more. – Sachin Apr 01 '20 at 14:57
  • This is isn't correct for the standard Python turtle library -- did you test the original? Most of turtle's methods are aliased as top level functions upon loading so `your_name = turtle.textinput(...)` is perfectly valid given `import turtle`. – cdlane Apr 02 '20 at 03:40