Загрузка данных


import tkinter
SCREEN_SIZE = (800, 800)
midx = SCREEN_SIZE[0]//2
midy = SCREEN_SIZE[1]//2
main = tkinter.Tk()
canvas = tkinter.Canvas(main, bg='white', height=SCREEN_SIZE[0], width=SCREEN_SIZE[1])
graph_pos = [canvas, 0, 0]

def xs(x):
    return SCREEN_SIZE[0]//2 + x

def ys(y):
    return SCREEN_SIZE[1]//2 - y

def moveto(x, y):
    graph_pos[1] = x
    graph_pos[2] = y

def lineto(x, y, width=1, color='black'):
    graph_pos[0].create_line(graph_pos[1:], (x, y),
                             width=width, fill=color)
    graph_pos[1] = x
    graph_pos[2] = y

def moveto(x, y):
    graph_pos[1] = x
    graph_pos[2] = y

def lineto(x, y, width=1, color='black'):
    graph_pos[0].create_line(graph_pos[1:], (x, y),
                             width=width, fill=color)
    graph_pos[1] = x
    graph_pos[2] = y

def decart():
    moveto(xs(0), ys(midy))
    lineto(xs(0), ys(-midy))
    moveto(xs(midx), ys(0))
    lineto(xs(-midx), ys(0))
r = 30
xus = 0
yus = 0
color = 'red'
def draw(event):
    global xus, yus
    step = 10
    if event.keysym == ('Up'):
        yus += step
    if event.keysym == ('Down'):
        yus -= step
    if event.keysym == ('Left'):
        xus -= step
    if event.keysym == ('Right'):
        xus += step
    limx = midx
    limy = midy
    if xus > limx:
        xus = -limx
    elif xus < -limx:
        xus = limx
    elif yus > limy:
        yus = -limy
    elif yus < -limy:
        yus = limy
    canvas.coords(ball, xs(xus) - r, ys(yus) - r, xs(xus) + r, ys(yus) + r)
    label.config(text=f'Координаты: ({xus}, {yus}), цвет: {color}')
ball = canvas.create_oval(xs(xus) - r, ys(yus) - r, xs(xus) + r, ys(yus) + r, fill = color)
label = tkinter.Label(main, text=f'Координаты: ({xus}, {yus}), цвет: {color}')
label.pack()
main.bind('<KeyPress>, draw')
decart()
canvas.pack()
main.mainloop()