I'm having a problem stopping the 'feed'; the cancel argument doesn't seem to have any impact on the after method. Although "feed stopped" is printed to the console.
I'm attempting to have one button that will start the feed and another that will stop the feed.
from Tkinter import Tk, Button import random def goodbye_world(): print "Stopping Feed" button.configure(text = "Start Feed", command=hello_world) print_sleep(True) def hello_world(): print "Starting Feed" button.configure(text = "Stop Feed", command=goodbye_world) print_sleep() def print_sleep(cancel=False): if cancel==False: foo = random.randint(4000,7500) print "Sleeping", foo root.after(foo,print_sleep) else: print "Feed Stopped" root = Tk() button = Button(root, text="Start Feed", command=hello_world) button.pack() root.mainloop()
With the output:
Starting Feed Sleeping 4195 Sleeping 4634 Sleeping 6591 Sleeping 7074 Stopping Feed Sleeping 4908 Feed Stopped Sleeping 6892 Sleeping 5605