I want to define a function that draws a shape using turtle graphics. I want the function to be able to clear the turtle graphics window once it is called again. Is there a way to do this or a way that I can close the turtle window once it's done and you press a certain key?
This is the function in question:
import turtle
import math
turtle
def draw(b, d, w, h):
bDraw = b*10
dDraw = d*10
wDraw = w*10
hDraw = h*10
bdAngle = abs(math.atan(dDraw/bDraw)*180/math.pi)
draw = turtle.Turtle()
draw
draw.right(90)
draw.forward(hDraw)
draw.left(90)
draw.forward(wDraw)
draw.left(90)
draw.forward(hDraw)
draw.right(90)
draw.forward(bDraw)
draw.left(180-bdAngle)
draw.forward(math.sqrt(dDraw**2 + bDraw**2))
draw.left(bdAngle)
draw.forward(wDraw)
draw.left(90-(180-bdAngle-90))
draw.forward(math.sqrt(dDraw**2 + bDraw**2))
draw.left(180-bdAngle)
draw.forward(bDraw+wDraw)