Поскольку вы новичок в кодировании, важной концепцией, если вы хотите, чтобы переменные из функции вне этой функции, было понятие scope , я предлагаю вам ознакомиться с ней. Что вы можете сделать, так это ввести переменную в «глобальной» области видимости, к которой вы добавляете:
import turtle
import math
t = turtle.Turtle()
wn = turtle.Screen()
click_positions = [] # will hold list of (x,y) click positions
def rounds(x, y):
t.setheading(t.towards(x, y)) #set x and y coord to mouse
t.up()
t.goto(x, y - 8) #move turtle to center of circle
t.setheading(0) #makes turtle face set direction
t.down()
t.begin_fill()
t.circle(8)
t.end_fill()
click_positions.append((x,y)) # build a list of click positions in click_positions
return x, y
def getcoord(): #draw function
turtle.onscreenclick(rounds, 1) #run round every time left click
turtle.mainloop() # loops on screen click
Вы должны хранить позиции щелчков в одном списке, а не в двух отдельных списках. В другом файле вы можете получить доступ к данным:
from your_filename import click_positions
for click in click_positions:
click_x, click_y = click # unpacks the python tuple (x,y) into two variables such that click_x=x, click_y=y