How to display count-down timers at specific times of the day?
Python with tkinter
outputs the fastest and easiest way to create the GUI applications and widget. Creating a GUI using tkinter
is an easy task.
You just need to use the following command to install the tkinter
apt-get install python-tk python3-tk
For Fedora users, use the following command.
dnf install python-tkinter python3-tkinter
This is a simple script for countdown with tkinter
, always ontop and transparent:
import tkinter as tk
from datetime import datetime, time
def dateDiffInSeconds(date1, date2):
timedelta = date2 - date1
return timedelta.days * 24 * 3600 + timedelta.seconds
def daysHoursMinutesSecondsFromSeconds(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return (days, hours, minutes, seconds)
def counter_label(label):
leaving_date = datetime.strptime('2022-01-01 01:00:00', '%Y-%m-%d %H:%M:%S') #end time to count down
def count():
now = datetime.now()
counter = daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, leaving_date))
label.config(text=str("%d days, %d hours, %d minutes, %d seconds" % counter))
label.after(1000, count)
count()
root = tk.Tk()
root.attributes('-topmost', True) #always on top
root.title("Counting Seconds") #title
label = tk.Label(root, fg="dark green") #font color
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy) #stop button
button.pack()
root.wait_visibility(root)
root.wm_attributes('-alpha',0.5) # transparent windows 0.1 - 1
root.mainloop()
With xfce4-genmon-plugin, you can create such a panel widget yourself.
Install the plugin from your distro's repositories. Then create a script which generates the countdown display:
#!/usr/bin/env python3
from datetime import date, time, datetime
now = datetime.now()
def show_countdown(target, event):
if now >= target:
print(("{} NOW!").format(event))
return
time_left = target - now
min, sec = divmod(time_left.seconds, 60)
hrs, min = divmod(min, 60)
print("{} in {}:{:02}:{:02}".format(event, hrs, min, sec))
show_countdown(
datetime.combine(date.today(), time(10, 25)),
"Cleanup"
)
show_countdown(
datetime.combine(date.today(), time(10, 30)),
"Class ends"
)
Modify it as you see fit, save it in some unobtrusive place and grant it execution permission (chmod +x
). Then add a "Generic monitor" item to your panel. Point the panel item to your script and configure a suitable refresh interval (if you removed seconds display, you should probably leave it at 30 seconds to save power/performance). And there you have it.
There are many ways and widgets to have a timer or countdown, but considering you are using xfce and want something graphical on the panel, you might want to try xfce4-timer-plugin.
It does require xfce >= 4.6 though. I don't know which version of xfce you are running, but this plugin might very well work for your needs.
The xfce4-timer-plugin allows you to set a countdown and an alarm with repeat options if you wish to set it daily for example,:
It also displays a countdown bar in the panel if you wish:
Countdown running:
Countdown empty:
You can read more about the plugin in the link above, but, here is the about and usage paragraphs just in case:
About
This is a simple plugin that lets the user run an alarm at a specified time or at the end of a specified countdown period.
Usage
The plugin is quite simple – it displays a progressbar showing the percentage of the time elapsed. Left-clicking on the plugin area opens a menu of available alarms. After selecting one, the user can start or stop the timer by selecting “start/stop timer” entry in the same menu. New alarms are added through the preferences window. Each alarm is either a countdown or is run at a specified time. By default a simple dialog pops up at the end of the countdown. The user can choose an external command to be run as the alarm and may also choose to have this repeated a specified number of times with a given interval between repetitions.