Disable Key Repeat in Tkinter
Use Tkinter's after() to pause the infinite loop for a short period of time. A shorter example.
from Tkinter import *class BounceTest(): def __init__(self): self.running=True self.window = Tk() canvas = Canvas(self.window, width = 400, height = 300) canvas.grid() x0 = 10 y0 = 50 x1 = 60 y1 = 100 i = 0 deltax = 2 deltay = 3 which = canvas.create_oval(x0,y0,x1,y1,fill="red", tag='red_ball') Button(text="Stop", bg='yellow', command=self.stop_it).grid(row=1) while self.running: canvas.move('red_ball', deltax, deltay) canvas.after(20) ## give it time to draw everything canvas.update() if x1 >= 400: deltax = -2 if x0 < 0: deltax = 2 if y1 > 290: deltay = -3 if y0 < 0: deltay = 3 x0 += deltax x1 += deltax y0 += deltay y1 += deltay self.window.mainloop() def stop_it(self): self.running=FalseBounceTest()