This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I am new to using Python and Tkinter. I am editing some code I found online that is a program that counts down to a set date. I have already made some simple changes to make it display 0:00:00 when the time hits 0 instead of going negative. But I would like to make the text flash when it hits 0. I assuming this could be done by changing the text color between green2(Original text color) and gray9(Background color). But, I have very little knowledge of Tkinter and Python and wasn't able to find any information online.
\#!/usr/bin/python
from tkinter import \*
from tkinter import ttk
from tkinter import font
import time
import datetime
global endTime
def quit(\*args):
root.destroy()
def show\_time():
\# Get the time remaining until the event
remainder = endTime - [datetime.datetime.now](https://datetime.datetime.now)()
\# remove the microseconds part
remainder = remainder - datetime.timedelta(microseconds=remainder.microseconds)
\# Show the time left
if endTim > [datetime.datetime.now](https://datetime.datetime.now)():
txt.set(remainder)
elif endTime < [datetime.datetime.now](https://datetime.datetime.now)():
txt.set("0:00:00")
\# Trigger the countdown after 1000ms
root.after(1000, show\_time)
\# Use tkinter lib for showing the clock
root = Tk()
root.attributes("-fullscreen", True)
root.configure(background='gray9')
root.bind("x", quit)
root.bind('<Escape'>, quit)
root.after(1000, show\_time)
\# Set the end date and time for the countdown
endTime = datetime.datetime(2019, 4, 25, 16, 0, 0)
fnt = font.Font(family='Helvetica', size=120, weight='bold')
txt = StringVar()
lbl = ttk.Label(root, textvariable=txt, font=fnt, foreground="green2", background="gray9")
lbl.place(relx=0.5, rely=0.5, anchor=CENTER)
root.mainloop()
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...