Advertisement
user_137

Tkinter Time Button

May 30th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. import Tkinter as tk
  4. import subprocess
  5. import datetime
  6. import time
  7. import sys
  8.  
  9. def getButton():
  10.     utc_time_on_your_pc = datetime.datetime.utcnow().replace(microsecond=0)
  11.     timer = datetime.datetime(2013, 5, 30, 14, 0, 0) - utc_time_on_your_pc
  12.     if timer < datetime.timedelta(0):
  13.         timer = datetime.datetime(2013, 6, 4, 2, 0, 0) - utc_time_on_your_pc
  14.     return ": : :  "+str(timer)+"  : : :"
  15.  
  16. def task():
  17.     """
  18.    This is a wrapper to repeatedly run another function
  19.    """
  20.     button["text"] = getButton()
  21.     root.after(500, task)
  22.  
  23.  
  24. def quit():
  25.     """
  26.    When the button is pressed this will exit to system
  27.    """
  28.     global root
  29.     root.quit()
  30.     sys.exit(0)
  31.  
  32. if __name__ == '__main__':
  33.     root = tk.Tk()
  34.     while 1:
  35.         button = tk.Button(root, text=getButton(), command=quit)
  36.         button.pack()
  37.         root.after(2000, task)
  38.         root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement