Python Turtle.Terminator even after using exitonclick()

Your turtle program is structured incorrectly. You needn’t do:

tw = t.Screen()
...
tw.exitonclick()

in every function. Screen() only needs to be called once; exitonclick() should only ever be called once. Try this restructuring:

import turtle as t

def square():
    for i in range(4):
        t.forward(100)
        t.right(90)

def triangle():
    for i in range(3):
        t.forward(100)
        t.right(120)

def star():
    for i in range(5):
        t.forward(150)
        t.right(144)

t.penup()
t.goto(150, 150)
t.pendown()
square()

t.penup()
t.goto(-150, 150)
t.pendown()
triangle()

t.penup()
t.goto(150, -150)
t.pendown()
star()

screen = t.Screen()
screen.exitonclick()

If you want to execute the code interactively, that’s fine too. Just drop everything after the function definitions, load it into Python interactively and do:

>>> star()

or whatever you want to run. You don’t need the call to Screen() and the exitonclick() doesn’t make sense when working interactively.

Leave a Comment