0% found this document useful (0 votes)
7 views2 pages

Clock Py

timer script

Uploaded by

fierypro125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Clock Py

timer script

Uploaded by

fierypro125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import tkinter as tk

from tkinter import ttk


from datetime import datetime

# Function to calculate the progress for day, month, and year


def calculate_progress():
now = datetime.now()

# Progress for the day


start_of_day = datetime(now.year, now.month, now.day)
end_of_day = datetime(now.year, now.month, now.day, 23, 59, 59)
progress_day = (now - start_of_day).total_seconds() / (end_of_day -
start_of_day).total_seconds()

# Progress for the month


start_of_month = datetime(now.year, now.month, 1)
end_of_month = datetime(now.year, now.month + 1, 1) if now.month != 12 else
datetime(now.year + 1, 1, 1)
progress_month = (now - start_of_month).total_seconds() / (end_of_month -
start_of_month).total_seconds()

# Progress for the year


start_of_year = datetime(now.year, 1, 1)
end_of_year = datetime(now.year + 1, 1, 1)
progress_year = (now - start_of_year).total_seconds() / (end_of_year -
start_of_year).total_seconds()

return progress_day, progress_month, progress_year, now

# Function to update the progress bars and the date display


def update_progress():
progress_day, progress_month, progress_year, now = calculate_progress()

# Update the progress bars


day_progress['value'] = progress_day * 100
month_progress['value'] = progress_month * 100
year_progress['value'] = progress_year * 100

# Update the labels to show the current date


day_label.config(text=f"Day Progress: {now.day}/{now.month}/{now.year} -
{progress_day*100:.2f}%")
month_label.config(text=f"Month Progress: {now.month}/{now.year} -
{progress_month*100:.2f}%")
year_label.config(text=f"Year Progress: {now.year} - {progress_year*100:.2f}%")

# After a set interval, call this function again


root.after(1000, update_progress)

# Create the main window


root = tk.Tk()
root.title("Progress of Day, Month, and Year")

# Create labels for displaying progress


day_label = tk.Label(root, text="Day Progress")
day_label.pack(pady=10)

month_label = tk.Label(root, text="Month Progress")


month_label.pack(pady=10)
year_label = tk.Label(root, text="Year Progress")
year_label.pack(pady=10)

# Create the progress bars


day_progress = ttk.Progressbar(root, length=300, mode='determinate', maximum=100)
day_progress.pack(pady=10)

month_progress = ttk.Progressbar(root, length=300, mode='determinate', maximum=100)


month_progress.pack(pady=10)

year_progress = ttk.Progressbar(root, length=300, mode='determinate', maximum=100)


year_progress.pack(pady=10)

# Initial call to update progress


update_progress()

# Start the Tkinter event loop


root.mainloop()

You might also like