Advertisement
here2share

# Tk_timer.py

Aug 9th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # Tk_timer.py
  2.  
  3. try:
  4.     # Python2
  5.     import Tkinter as tk
  6. except ImportError:
  7.     # Python3
  8.     import tkinter as tk
  9. import time
  10.  
  11. minutes=60
  12. def count_down():
  13.     for t in range(minutes*2, -1, -1):
  14.         sf = "{:02d}:{:02d}".format(*divmod(t, 60))
  15.         time_str.set(sf)
  16.         try:
  17.             root.update()
  18.         except:
  19.             return
  20.         time.sleep(1)
  21.  
  22.  
  23. root = tk.Tk()
  24. time_str = tk.StringVar()
  25. label_font = ('helvetica', 40)
  26. tk.Label(root, textvariable=time_str, font=label_font, bg='white',
  27.          fg='blue', relief='raised', bd=3).pack(fill='x', padx=5, pady=5)
  28. time_str.set('00:00')
  29. root.update()
  30. tk.Button(root, text='Count Start', command=count_down).pack()
  31. tk.Button(root, text='Count Stop', command=root.destroy).pack()
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement