Question: import turtle as t import threading def save _ drawing ( x _ list, y _ list, file _ name ) : with open (
import turtle as t
import threading
def savedrawingxlist, ylist, filename:
with openfilename, w as file:
for x y in zipxlist, ylist:
file.writefxy
def stopdrawingx y:
global continuedrawing
continuedrawing False
def handleclickx y:
global points
points.appendx y
tgotox y
tdot
def main:
global points, continuedrawing
tspeed
thideturtle
fillcolor ttextinputInput 'Enter fill color:
tfillcolorfillcolor
bgcolor ttextinputInput 'Enter background color:
tScreenbgcolorbgcolor
# Initial drawing
points
tonscreenclickhandleclick, # Leftclick
tonscreenclickfinalizeshape, # Rightclick
tonscreenclickstopdrawing, # Middleclick scroll wheel click
tpenup
tgoto
twriteInitial Drawing: Leftclick to add points, rightclick to finish, middleclick to stop", fontArial "normal"
tmainloop
# Allow user to draw additional shapes
continuedrawing True
while continuedrawing:
treset # Reset the screen before drawing a new shape
points
# Instructions
tonscreenclickhandleclick, # Leftclick
tonscreenclickfinalizeshape, # Rightclick
tonscreenclickstopdrawing, # Middleclick scroll wheel click
tpenup
tgoto
twriteLeftclick to add points, rightclick to finish, middleclick to stop", fontArial "normal"
if not continuedrawing:
filename ttextinputSave Drawing", "Enter filename to save the drawing:"
if filename:
savedrawingfilename points
def finalizeshapex y:
global continuedrawing
if lenpoints:
tpenup
tgotox y
choice ttextinputChoose "Straight S or Curve CEnter to continue drawing, Q to quitupper
if choice S:
drawpolygonpoints if lenpoints else tgotopoints
elif choice C:
drawcurvepoints
elif choice Q:
global continuedrawing
continuedrawing False
tpenup
points.clear
def togglepenx y:
if tisdown:
tpenup
else:
tpendown
def drawpolygonpoints:
tpenup
tbeginfill
tgotopoints
tpendown
for point in points::
tgotopoint
tgotopoints
tendfill
def draw
curvepoints:
tbeginfill
for i in range lenpoints:
P pointsi pointsi pointsi pointsi
for o in range:
x beziero P P P P
y beziero P P P P
tgotox y
if o :
tpendown
tendfill
def beziero p p p p:
return o p o o p o o p o p
if namemain:
main
def loaddrawingfilename:
xlist
ylist
try:
with openfilename, r as file:
for line in file:
x y mapfloat line.stripsplit
xlist.appendx
ylist.appendy
except FileNotFoundError:
printFile not found."
return xlist, ylist
this program is stuck on a loop and I cannot find a way for it stop drawing and save the coordinates of the places clicked on turtle screen into a text file
help me make this program be able to save and load drawings
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
