-
Notifications
You must be signed in to change notification settings - Fork 130
Feat/digital clock improvements #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
15f2d8d
db19bc8
0173fc9
026b56e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,23 +1,50 @@ | ||||||
from time import strftime | ||||||
from tkinter import Label, Tk | ||||||
from tkinter import Label, Tk , Button | ||||||
|
||||||
window = Tk() | ||||||
window.title("Digital Clock") | ||||||
window.geometry("300x100") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The window height of 100px may be insufficient to accommodate the new date label and toggle button. Consider increasing the height to ensure all elements are visible without overlapping.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
window.configure(bg="green") | ||||||
window.resizable(False, False) | ||||||
|
||||||
use_24h = True | ||||||
|
||||||
clock_label = Label( | ||||||
window, bg="black", fg="green", font=("Arial", 30, "bold"), relief="flat" | ||||||
) | ||||||
clock_label.place(x=50, y=50) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using both
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
|
||||||
date_label = Label( | ||||||
window, bg="black", fg="white", font=("Arial", 14) | ||||||
) | ||||||
date_label.pack(pady=(0, 10), anchor="center") | ||||||
|
||||||
|
||||||
|
||||||
def toggle_format(_evt=None): | ||||||
global use_24h | ||||||
use_24h = not use_24h | ||||||
fmt_btn.config(text="Switch to 24-hour" if not use_24h else "Switch to 12-hour") | ||||||
|
||||||
fmt_btn = Button(window, text="Switch to 12-hour", command=toggle_format) | ||||||
fmt_btn.pack(pady=(0, 8)) | ||||||
window.bind("<f>", toggle_format) # press 'f' to toggle | ||||||
|
||||||
|
||||||
|
||||||
def update_label(): | ||||||
current_time = strftime("%H: %M: %S\n %d-%m-%Y ") | ||||||
clock_label.configure(text=current_time) | ||||||
clock_label.after(80, update_label) | ||||||
clock_label.pack(anchor="center") | ||||||
|
||||||
if use_24h: | ||||||
time_text = strftime("%H:%M:%S") | ||||||
else: | ||||||
# strip leading zero in 12h mode for a cleaner look | ||||||
time_text = strftime("%I:%M:%S %p").lstrip("0") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
clock_label.configure(text=time_text) | ||||||
date_label.configure(text=strftime("%A, %b %d, %Y")) | ||||||
window.after(1000, update_label) | ||||||
|
||||||
update_label() | ||||||
window.mainloop() | ||||||
window.mainloop() | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation includes the current day (
localtime.tm_mday
) which represents a partial day, but then multiplies by 24 hours as if it were complete days. This creates inaccurate hour/minute/second calculations. Consider excluding the current partial day or adjusting the calculation to account for the actual time of day.Copilot uses AI. Check for mistakes.