import turtle
import atexit
x1 = 0
y1 = 0
x2 = 0
y2 = 0
click = 0
f = open("demofile.py", "w")
f.write("import turtle\n")
def insertloop():
f.write("turtle.mainloop()\n")
atexit.register(insertloop)
def func_on_screen(x, y):
global x1
global y1
global x2
global y2
global click
global f
if click == 0:
x1 = x
y1 = y
print ("click 1")
print (x1,y1)
f.write(f"turtle.goto({x1},{y1})\n")
if click == 1:
x2 = x
y2 = y
print ("click 2")
print (x2,y2)
f.write(f"turtle.goto({x2},{y2})\n")
draw_line(x1,y1,y2,x2)
click = click + 1
if click == 2:
click = 0
def draw_line(x1,y1,y2,x2):
turtle.goto(x1,y1)
turtle.goto(x2,y2)
turtle.onscreenclick(func_on_screen)
turtle.mainloop()
|