AttributeError invalid type object has no attribute pen on line 2

0 votes
import turtle

t=turtle.pen()

t.color(1,0,0)

t.begin_fill()

t.forward(250)

t.left(144)

t.forward(250)

t.left(144)

t.forward(250)

t.left(144)

t.forward(250)

t.left(144)

t.forward(250)

t.end_fill()

I have a problem. It has an error like this - 

AttributeError: '<invalid type>' object has no attribute 'pen' on line 2

 Help me pls!

Nov 25, 2020 in Python by anonymous
• 170 points
3,523 views

2 answers to this question.

+2 votes
Best answer

Hello,

Turtle.pen is used to set/get pen attributes of turtle but not to draw(see help(turtle.pen) for more info), in order to draw something you need to get Turtle object as follow:

import turtle
tur=turtle.Turtle();
tur.forward(50);
answered Nov 25, 2020 by Niroj
• 82,880 points

selected Nov 26, 2020 by Black_Mesa
+1 vote

Hey, @There,

Did you happen to create a module or file called sys? If so you are importing from your local module rather than from the built-in Python sys module

Otherwise, these import commands are case sensitive, make sure everything is in lower case (it is in your post, but you never know):

f

Without the brackets (i.e. without entering pen() or Pen()), Python just prints out a simple description, so we can see that pen is a function, and Pen is a class (good rule of thumb: names which start with an uppercase letter are generally classes, names with a lowercase letter are functions, variables, and so on). For the example code, we want to create a Pen object (we don't want to call the pen function) - so if you change your code to...

import turtle
t = turtle.Pen()
answered Nov 25, 2020 by Gitika
• 65,910 points
Not working((

Related Questions In Python

0 votes
1 answer

Getting error "AttributeError: 'Screen' object has no attribute 'title' on line 8"

Hey @TedTickles,  Replace  wn.update() with turtle.up ...READ MORE

answered Dec 24, 2020 in Python by Gitika
• 65,910 points
3,442 views
0 votes
1 answer

AttributeError: type object 'DataFrame' has no attribute 'from_items'

Hi, @Bronson, You can go through this, I ...READ MORE

answered Apr 6, 2020 in Python by Gitika
• 65,910 points
4,971 views
0 votes
1 answer

AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

Hi@akhtar, I think numpy version is not compatible ...READ MORE

answered Apr 13, 2020 in Python by MD
• 95,440 points
13,754 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,560 points
8,900 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,409 views
0 votes
2 answers

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

Try this: data=pd.read_csv('/your file name', delim_whitespace=Tru ...READ MORE

answered Dec 10, 2020 in Python by anonymous
• 82,880 points
129,976 views
0 votes
1 answer

Error:AttributeError: 'module' object has no attribute 'tests'

Hello @kartik, The problem was that test couldn't find ...READ MORE

answered Aug 7, 2020 in Python by Niroj
• 82,880 points
11,530 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP