Skip to content

Instantly share code, notes, and snippets.

@raresteak
Last active January 9, 2022 13:59
Show Gist options
  • Save raresteak/dfff2f29c64eddb3b1c107e4f0a49780 to your computer and use it in GitHub Desktop.
Save raresteak/dfff2f29c64eddb3b1c107e4f0a49780 to your computer and use it in GitHub Desktop.
Countdown timer gui written in Python with tkinter
#!/usr/bin/python3
# Windowed countdown timer
# USAGE: update the duration variable on line 9.
# Author: Raresteak
# https://github.com/raresteak
import time
from tkinter import *
# Countdown timer duration in seconds
duration = 3600
def stopwatch(sec):
while sec:
if (sec <= duration/2):
# Update window color to yellow as warning half time has expired.
theWindow.configure(bg='yellow')
theWindow.update()
if (sec == 1):
# update window color to red, time is expired
theWindow.configure(bg='red')
theWindow.update()
windowContents = Label(theWindow, text="Time is up!")
windowContents.pack()
minn, secc = divmod(sec, 60)
timeformat = '{:02d}:{:02d}'.format(minn, secc)
theWindow.title("Time remaining: " + timeformat)
theWindow.update()
time.sleep(1)
sec -= 1
theWindow = Tk()
theWindow.attributes('-topmost', 1)
theWindow.geometry("300x30+680+0")
theWindow.configure(bg='green')
stopwatch(duration)
theWindow.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment