I am working on a project in python, and I made a method to draw a specific thing in tkinter. I want it so that whenever I press the spacebar, the image will redraw itself (run the method again because I coded the method so that it could redraw over itself). How exactly would I bind the spacebar to the method so that the program would run, draw, and re-draw if I pressed the spacebar?
for example, i want it so that whenever I press space, the program draws in a random location on the canvas:
from Tkinter import *
from random import *
root=Tk()
canvas=Canvas(root,width=400,height=300,bg='white')
def draw():
canvas.delete(ALL)# clear canvas first
canvas.create_oval(randint(0,399),randint(0,299),15,15,fill='red')
draw()
canvas.pack()
root.mainloop()
how would i bind the spacebar to the method?