Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python I am making a Snake game using turtle and have a "raise terminator turtle.terminator" error.

Nathan Hadley

New Coder
I would like it to run rather than terminate itself:

Python:
#//Snake
#Import random for spawns, turle for graphics, time for pauses, and urllib for downloading icon
import random
import turtle
import time
import urllib.request

#//Downloading...
print("Downloading necessary files...")
#//Icon download
iconURL = "https://freepngimg.com/download/symbol/82731-symbol-grass-snake-slitherio-pass-free-transparent-image-hq.png"
icon = urllib.request.urlretrieve(iconURL, 'c:/ProgramData/icon.png')
print()
print("Download complete")
print("Launching game...")

#//Window creation
wn = turtle.Screen()
wn.setup(width = 1.0, height = 1.0)
canvas = wn.getcanvas()
root = canvas.winfo_toplevel()
root.overrideredirect(1)
wn.title('Snake')
wn.bgcolor('olive drab')
wn.tracer(0)

#//Snake character creation
head = turtle.Turtle()
head.shape("square")
head.color("white")
head.penup()
head.goto(0, 0)
head.direction = "Stop"

#//Food spawn
food = turtle.Turtle()
colors = 'blue'
shapes = random.choice(['square', 'triangle', 'circle'])
food.speed(0)
food.shape(shapes)
food.color(colors)
food.penup()
food.goto(0, 100)

#//Movement creations
def up():
    if head.direction != "down":
        head.direction = "up"

def down():
    if head.direction != "up":
        head.direction = "down"

def left():
    if head.direction != "right":
        head.direction = "left"  

def right():
    if head.direction != "left":
        head.direction = "right"

def slither():
    if head.direction == "up":
            y = head.ycor()
            head.sety(y+20)
    if head.direction == "down":
            y = head.ycor()
            head.sety(y-20)
    if head.direction == "left":
            x = head.xcor()
            head.setx(x-20)
    if head.direction == "right":
            x = head.xcor()
            head.setx(x+20)

#//Keypresses
wn.listen()
wn.onkeypress(up(), 'w')
wn.onkeypress(down(), 's')
wn.onkeypress(left(), 'a')
wn.onkeypress(right(), 'd')

#//Segments
segments = []
delay = 0.0

#//Gameplay
while True:
    wn.update()
    if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
        time.sleep(1)
        head.goto(0, 0)
        head.direction = "stop"
        colors = random.choice(['green', 'deep sky blue', 'dark slate blue'])
        shapes = 'square'
        for segment in segments:
            segment.goto(1000, 1000)
        segments.clear()
        delay = 0.1
   
    if head.distance(food) < 20:
        x = random.randint(-270, 270)
        y = random.randint(-270, 270)
        food.gotot(x, y)
        new_segment = turtle.Turtle()
        new_segment.speed(0)
        new_segment.shape("square")
        new_segment.color("orange")
        new_segment.penup()
        segments.append(new_segment)
        delay -= 0.001
       
    for index in range(len(segments)-1, 0, -1):
        x = segments[index-1].xcor()
        y = segments[index-1].ycor()
        segments[index].goto(x, y)
        if len(segments) > 0:
                x = head.xcor()
                y = head.ycor()
                segments[0].goto(x, y)
        move()
        for segment in segments:
            if segment.distance(head) < 20:
                        time.sleep(1)
                        head.goto(0, 0)
                        head.direction = "stop"
                        colors = random.choice(['red', 'blue', 'green'])
                        shapes = random.choice(['square', 'circle'])
                        for segment in segments:
                            segment.goto(1000, 1000)
                        segment.clear()
    time.sleep(delay)

wn.mainloop()


I get this error maessage:

Traceback (most recent call last):
File "C:\Users\pigeo\Downloads\Snake.py", line 89, in <module>
wn.update()
File "C:\Users\pigeo\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1304, in update
t._update_data()
File "C:\Users\pigeo\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2647, in _update_data
self.screen._incrementudc()
File "C:\Users\pigeo\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1293, in _incrementudc
raise Terminator
turtle.Terminator
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom