wishamg17
wishamg17

Reputation: 21

I don't know what I'm misssing(Turtle)

I'm using Trinket to run my python.

I have been tinkering with it for days and it keeps giving me this error:

Traceback (most recent call last):   File
"/tmp/sessions/5ecd67058b43cfc0/main.py", line 2, in
    setup(500, 500)   File "", line 6, in setup   File "/usr/lib/python3.5/turtle.py", line 3662, in Screen
    Turtle._screen = _Screen()   File "/usr/lib/python3.5/turtle.py", line 3678, in __init__
    _Screen._root = self._root = _Root()   File "/usr/lib/python3.5/turtle.py", line 434, in __init__
    TK.Tk.__init__(self)   File "/usr/lib/python3.5/tkinter/__init__.py", line 1871, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

Here is the code so far:

from turtle import *
setup(500, 500)
Screen()
title("Turtle Keys")
move = Turtle()
showturtle()
def k1():
 move.forward(100)
 move.left(90)
 move.forward(100)
 move.left(90)
 move.forward(100)
 move.left(90)
 move.forward(100)
 move.left(90)
def k2():
 move.forward(320)
 move.left(120)
 move.forward(320)
 move.left(120)
 move.forward(320)
 move.left(120)
 
def k3():
    move.right(45)
def k4():
 move.forward(100)
 move.left(90)
 move.forward(50)
 move.left(90)
 move.forward(100)
 move.left(90)
 move.forward(50)
 move.left(90)
 
def k5():
 move.left(10)
 
def k6():
 move.forward(10)
 
def k7():
 move.backward(10)
 
onkey(k1, "Up")
onkey(k2, "Left")
onkey(k3, "Right")
onkey(k4, "Down")
onkey(k5, "1")
onkey(k6, "2")
onkey(k7, "3")
listen()
mainloop()

The objective is to draw certain shapes when certain keys are pressed.

Upvotes: 2

Views: 3380

Answers (2)

Ed Randall
Ed Randall

Reputation: 7610

repl.it at least supports graphics and tells you the errors in your program instead of the unhelpful $DISPLAY variable error - Try https://repl.it/languages/python_turtle.

But it still doesn't seem to support keyboard input that you are trying to use. If you comment out setup() and title() and also remove the onkey() / listen() code, replacing instead with some hard calls to your functions, you can at least get some output.

Install Python locally - https://www.python.org/downloads/ - to get a full-featured environment.

Upvotes: 0

Wayne Werner
Wayne Werner

Reputation: 51917

If you're talking about https://trinket.io/python, it looks like you haven't read the docs too closely - there's a limited subset of Turtle that Trinket actually supports, and none of it involves user interaction.

If you want to have keyboard interaction and Turtle, you're going to need to install Python on your own machine

Upvotes: 2

Related Questions