Skip to content

Instantly share code, notes, and snippets.

@vampjaz
Last active November 25, 2016 11:43
Show Gist options
  • Save vampjaz/072d232af8ffec60ee2c to your computer and use it in GitHub Desktop.
Save vampjaz/072d232af8ffec60ee2c to your computer and use it in GitHub Desktop.
FRC countdown - python countdown.py <unix timestamp>
import time
from Tkinter import *
import sys
END = int(sys.argv[1]) # epoch in seconds
RATE = 50
font1 = ("Helvetica", 30, 'bold')
font2 = ("Helvetica", 28)
root = Tk()
days = IntVar()
hrs = IntVar()
mins = IntVar()
secs = IntVar()
msecs = IntVar()
lbl_days = Label(root, textvariable=days, font=font1, width=3)
lbl_dayl = Label(root, text='days', font=font2)
lbl_hrs = Label(root, textvariable=hrs, font=font1, width=2)
lbl_hrl = Label(root, text='hrs', font=font2)
lbl_mins = Label(root, textvariable=mins, font=font1, width=2)
lbl_minl = Label(root, text='mins', font=font2)
lbl_secs = Label(root, textvariable=secs, font=font1, width=2)
lbl_secl = Label(root, text='secs', font=font2)
lbl_msecs = Label(root, textvariable=msecs, font=font1, width=4)
lbl_msecl = Label(root, text='ms', font=font2)
lbl_days.grid(row=0,column=0)
lbl_dayl.grid(row=0,column=1)
lbl_hrs.grid(row=0,column=2)
lbl_hrl.grid(row=0,column=3)
lbl_mins.grid(row=0,column=4)
lbl_minl.grid(row=0,column=5)
lbl_secs.grid(row=0,column=6)
lbl_secl.grid(row=0,column=7)
lbl_msecs.grid(row=0,column=8)
lbl_msecl.grid(row=0,column=9,sticky=E)
lbl2 = Label(root, text="countdown", font=font2)
lbl2.grid(row=1,column=0,columnspan=7,sticky=E)
#root.geometry('550x80')
def update():
diff = END-time.time()
stime = time.gmtime(diff)
msec = int((diff%1)*1000)
days.set(stime.tm_yday-1) # can only be less than a year
hrs.set(stime.tm_hour)
mins.set(stime.tm_min)
secs.set(stime.tm_sec)
msecs.set(msec)
root.after(RATE,update)
root.after(RATE,update)
root.mainloop()
@FoxtrotOscar
Copy link

Hi,
I'm attempting to understand your code - but I'm getting an error when I attempt to run it:
File "/home/pi/Downloads/Countdown.py", line 5, in
END = int(sys.argv[1]) # epoch in seconds
IndexError: list index out of range

Any chance you could explain this as I'm struggling...

Py 2.7 or 3, Pi 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment