-2
window=turtle.Screen()
window.title("Pong")
window.bgcolor("black")
window.setup(width=800,height=600)
window.tracer(0)
 File "C:\Users\Aditya\PycharmProjects\pythonProject\main.py", line 6, in <module>
    window=turtle.Screen()
NameError: name 'turtle' is not defined
martineau
  • 112,593
  • 23
  • 157
  • 280

3 Answers3

0

I think you forgot to import turtle

import turtle
window=turtle.Screen()
window.title("Pong")
window.bgcolor("black")
window.setup(width=800,height=600)
window.tracer(0)
redystum
  • 334
  • 2
  • 8
0

You need to import the module before calling the sub-functions within it. In your case, you need the turtle module.

import turtle
window=turtle.Screen()
window.title("Pong")
window.bgcolor("black")
window.setup(width=800,height=600)
window.tracer(0)

However, if you added the line: import turtle, and encounter the error below:

File "/usr/lib/python3.8/turtle.py", line 107, in <module>
import tkinter as TK 
ModuleNotFoundError: No module named 'tkinter'

You may refer to this post: here

Blaco
  • 109
  • 7
-1

Have you imported the Turtle module? if you didn't, try this one:

from turtle import *

Then the rest of your code

  • This would not make the OP's code work as it imports everything in `turtle` into the current namespace. – Chris Jan 29 '22 at 19:32