nerdegutta.no
Python: New clock - updated with weekday
23.01.26
Programming
# This program show time and day
# import libraries
from tkinter import *
import time
import datetime
# Make a list of the Norwegian weekdays. 0=Monday
weekdays = ['Mandag', 'Tirsdag', 'Onsdag', 'TOrsdag', 'Fredag', 'Lørdag', 'Søndag']
# Get todays day as a number
today = datetime.datetime.today()
weekday_number = today.weekday()
# Function to uppdate time and day
def tick():
time_string=time.strftime("%H:%M")
clock.config(text=time_string)
today = datetime.datetime.now() # Update today
weekday_number = today.weekday() # Update weekday_number
day_of_week.config(text=weekdays[weekday_number])
clock.after(200, tick)
# Make the main window
window = Tk()
screenW = window.winfo_screenwidth() # Get actual screen width
screenH = window.winfo_screenheight() # Get actual screen height
window.geometry(f"{screenW}x{screenH}") # Set the width and height
window.overrideredirect(True) # Remove window decoration
window.configure(bg="black") # Set backgroundcolor to black
# Make the Label for the clocks digits
clock = Label(window, font=("serif", 250, "bold"), fg="white", bg="black") # Set font and colors
clock.grid(row=0, column=1) # Place the label in the grid
clock.place(relx=0.5, rely=0.5, anchor=S) # Place the label
# Make the day of week label
day_of_week = Label(window, font=("serif", 190, "bold"), fg="white", bg="black")
day_of_week.grid(row=0, column=1)
day_of_week.place(relx=0.5, rely=0.5, anchor=N)
# Make the quit button, and place it in the top left corner og the screen
quitButton = Button(window, text="x", fg="red", command=window.destroy)
quitButton.pack(side=TOP, anchor=NW)
tick()
window.title("Clock")
window.geometry("+0+0")
window.resizable(False, False)
window.mainloop()