import thread import time orient = 1 def fun(w): global orient if orient > 0: w.x += 5 if w.x > 1000: orient = -1 else: w.x -= 5 if w.x < 0: orient = 1 def fun2(w): while(True): fun(w) time.sleep(.1) def start(w): thread.start_new_thread(fun2, (w,))