Skip to content

Instantly share code, notes, and snippets.

@zed
Last active November 3, 2016 04:04
Show Gist options
  • Select an option

  • Save zed/74f62de8a4d99e4e9c399808c6e004e1 to your computer and use it in GitHub Desktop.

Select an option

Save zed/74f62de8a4d99e4e9c399808c6e004e1 to your computer and use it in GitHub Desktop.
tkinter loop
#!/usr/bin/env python3
"""Show how to implement a loop using tkinter."""
import itertools
import tkinter
def loop(widget, delay_ms=300, chars=itertools.cycle('\-/|')):
print(next(chars), end='\r', flush=True)
widget.after(delay_ms, loop, widget, delay_ms)
root = tkinter.Tk()
root.withdraw() # hide GUI
root.after_idle(loop, root) # start loop
root.after(5000, root.destroy) # quit in 5 seconds
root.mainloop()
print('done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment