from tkinter import *
x_center = 250
y_center = 250
r = 50
x_from_center = 0
y_from_center = 0
root = Tk()
canvas = Canvas(root, width=500, height=500, bg='purple')
oval = canvas.create_oval(x_center - r, y_center - r, x_center + r, y_center + r, fill='black')
def right(event):
global x_from_center
canvas.move(oval, 5, 0)
x_from_center += 5
def left(event):
global x_from_center
canvas.move(oval, -5, 0)
x_from_center -= 5
def up(event):
global y_from_center
canvas.move(oval, 0, -5)
y_from_center -= 5
def down(event):
global y_from_center
canvas.move(oval, 0, 5)
y_from_center += 5
def space(event):
global x_from_center, y_from_center
canvas.move(oval, x_from_center * (-1), y_from_center * (-1))
x_from_center = y_from_center = 0
root.bind('<Right>', right)
root.bind('<Left>', left)
root.bind('<Up>', up)
root.bind('<Down>', down)
root.bind('<space>', space)
canvas.pack()
root.mainloop()
x_from_center = y_from_center = 0
x_from_center = 0
y_from_center = 0