0
from random import choice
from turtle import *
from base import floor,vector
from tkinter import *
root=Tk()
state={'score':0}
path=Turtle(visible=False)
writer=Turtle(visible=False)
aim=vector(5,0)
pacman=vector(-40,-80)

ghosts=[
      [vector(-180,160),vector(5,0)], 
      [vector(-180,-160),vector(0,5)],       
      [vector(100,160),vector(0,-5)],
      [vector(100,-160),vector(-5,0)],
      
]
# 0 means that there is no path to move there.
# 1 means that there is there is path for movement.
tiles = [
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
    0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0,
    0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]

# This functions draws a square with bottom left corner as x and y
def square(x, y):
    "Draw square using path at (x, y)."
    path.up()
    path.goto(x, y)
    path.down()
    path.begin_fill()

    for count in range(4):
        path.forward(20)
        path.left(90)

    path.end_fill()

# Using offset we can find what will be the value of the tile at a particular position.
def offset(point):
    "Return offset of point in tiles."
    x = (floor(point.x, 20) + 200) / 20
    y = (180 - floor(point.y, 20)) / 20
    index = int(x + y * 20)
    return index

def valid(point):
    "Return True if point is valid in tiles."
    index = offset(point)

    if tiles[index] == 0:
        return False

    index = offset(point + 19)

    if tiles[index] == 0:
        return False

    return point.x % 20 == 0 or point.y % 20 == 0

def world():
    "Draw world using path."
    bgcolor('black')
    path.color('blue')

    for index in range(len(tiles)):
        tile = tiles[index]

        if tile > 0:
            x = (index % 20) * 20 - 200
            y = 180 - (index // 20) * 20
            square(x, y)

            if tile == 1:
                path.up()
                path.goto(x + 10, y + 10)
                path.dot(10, 'white')

canvas = Canvas (root, width=width,height= height)

shape=canvas.create_oval (width/2,height/2,width/2+10,height/2+10, fill="yellow")
canvas.pack(expand=YES,fill=BOTH)

def Left(event):
    x= -10
    y=-0
    canvas.move(shape,x,y)

def Right(event):
    x=10
    y=0
    canvas.move(shape,x,y)

def Up(event):
    x=0
    y=-10
    canvas.move(shape,x,y)

def Down(event):
    x=0
    y=10
    canvas.move(shape,x,y)

root.bind("<Left>",Left)
root.bind("<Right>",Right)
root.bind("<Up>",Up)
root.bind("<Down>",Down)
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
writer.goto(160, 160)
writer.color('black')
writer.write(state['score'])
listen()
world()
move()
done()
root.mainloop()

     ---------------------------------------------------------------------------
Terminator                                Traceback (most recent call last)
/var/folders/kp/c2snstb56kx1gh8rmg8n_w700000gp/T/ipykernel_11129/2369534156.py in <module>
      6 state={'score':0}
      7 path=Turtle(visible=False)
----> 8 writer=Turtle(visible=False)
      9 aim=vector(5,0)
     10 pacman=vector(-40,-80)

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py in __init__(self, shape, undobuffersize, visible)
   3812         if Turtle._screen is None:
   3813             Turtle._screen = Screen()
-> 3814         RawTurtle.__init__(self, Turtle._screen,
   3815                            shape=shape,
   3816                            undobuffersize=undobuffersize,

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py in __init__(self, canvas, shape, undobuffersize, visible)
   2556         self._undobuffersize = undobuffersize
   2557         self.undobuffer = Tbuffer(undobuffersize)
-> 2558         self._update()
   2559 
   2560     def reset(self):

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py in _update(self)
   2659             return
   2660         elif screen._tracing == 1:
-> 2661             self._update_data()
   2662             self._drawturtle()
   2663             screen._update()                  # TurtleScreenBase

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py in _update_data(self)
   2645 
   2646     def _update_data(self):
-> 2647         self.screen._incrementudc()
   2648         if self.screen._updatecounter != 0:
   2649             return

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/turtle.py in _incrementudc(self)
   1291         if not TurtleScreen._RUNNING:
   1292             TurtleScreen._RUNNING = True
-> 1293             raise Terminator
   1294         if self._tracing > 0:
   1295             self._updatecounter += 1

Terminator: 

I have no idea what this is but I hope someone will answer this. I got this after merging 2 python modules together and I think that is the problem but I would like to know if there is a way to have 2 python modules in the same set of code. I'm trying to make a maze game with turtle and tkinter now but which do you think is best to use anyway?

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
nev nev
  • 5
  • 6
  • Does this answer your question? [how to set a turtle to a turtle screen](https://stackoverflow.com/questions/44634947/how-to-set-a-turtle-to-a-turtle-screen) – Thingamabobs Aug 14 '22 at 11:22
  • yes but how do i implement that to my code? – nev nev Aug 14 '22 at 11:37
  • `done` and `mainloop` -- pick one or the other. It's supposed to be the [last statement in the turtle program](https://docs.python.org/3/library/turtle.html#turtle.done). Terminator errors typically occur when you try to call turtle methods after the window was destroyed. Where in the program is this occurring and please show a [mcve]. What do you mean by 2 python modules? – ggorlen Aug 14 '22 at 15:25
  • Here's a minimal terminator repro on 3.10.2: `import turtle;turtle.exitonclick();turtle.done()`. – ggorlen Aug 14 '22 at 15:35
  • Does this answer your question? [Python Turtle.Terminator even after using exitonclick()](https://stackoverflow.com/questions/45534458/python-turtle-terminator-even-after-using-exitonclick) – ggorlen Sep 21 '22 at 02:59

0 Answers0