Search code examples
pythongraphicspython-turtle

Dict not defined in turtle


from turtle import *

mypen = pen()
screen = Screen()

def graphics():
    mypen.forward(20)

Problem with Python not recognizing the pen function, and outputting "Dict not Defined"


Solution

  • You are trying to create an object of the class pen and assign it to a variable, which won't word because there is no class named "pen" in the turtle library. Since Python is case sensitive, pen and Pen are not the same thing, so to do what you seem to have intended, you would write "mypen = Pen()".

    But I don't think that is what you are intending to do, after all. Basically, in the turtle-framework, you would create a turtle-object with

    my_turtle = Turtle()
    

    which HAS a pen, and then set the properties of the pen by using

    my_turtle.pen(...)
    

    For how you can customize the pen, you best refer to the documentation of the turtle-library, which is very well documented: https://docs.python.org/3/library/turtle.html