Answer the question
In order to leave comments, you need to log in
How can I make the circle move further after pressing the space bar?
from tkinter import*
def DrawCircle(x,y,r):
h.create_oval(x-r,y-r,x+r,y+r,fill='black')
def right(event):
h.move(1,5,0)
def left(event):
h.move(1,-5,0)
def up(event):
h.move(1,0,-5)
def down(event):
h.move(1,0,5)
def space(event):
h.delete('all')
h['bg']='purple'
h.create_oval(x-r,y-r,x+r,y+r,fill='black')
root=Tk()
root.bind('<Right>',right)
root.bind('<Left>',left)
root.bind('<Up>',up)
root.bind('<Down>',down)
root.bind('<space>',space)
h=Canvas(root,width=500,height=500,bg='purple')
x=250
y=250
r=50
DrawCircle(x,y,r)
h.pack()
root.mainloop()
Answer the question
In order to leave comments, you need to log in
If my eyes do not fail me at 4 o'clock in the morning, then when I press the spacebar, another circle is created and it no longer has anything to do with events. Here you need to do this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question