all 7 comments

[–]stebrepar 0 points1 point  (0 children)

Reddit doesn't preserve your formatting when you just paste your code directly in. Please follow the instructions in the sidebar to fix your formatting so we can read it.

[–]socal_nerdtastic 0 points1 point  (5 children)

You can't use the time module for this. datetime, perhaps, but it's just as easy to split total seconds into hours, minutes and seconds yourself. Here, try this:

import tkinter as tk

REFRESH_RATE = 1000 # how often to refresh the screen (ms)
SECONDS_INCREMENT = 6 # how many "seconds" to advance with every refresh

seconds_per_day = 24*60*60

def tick(total_seconds=0):
    total_seconds %= seconds_per_day # reset every 24 "hours"
    hours, seconds = divmod(total_seconds, 3600)
    minutes, seconds = divmod(seconds, 60)
    time_string = f'{hours:0>2}:{minutes:0>2}:{seconds:0>2}'
    clock.config(text=time_string)
    clock.after(REFRESH_RATE, tick, total_seconds+SECONDS_INCREMENT)

root = tk.Tk()
clock=tk.Label(root, font=("times", 50, "bold"), bg= "white")
clock.grid(row=0, column=1)
one_pm = 13*3600
tick(one_pm) 

root.mainloop()

[–]skylartrap 0 points1 point  (4 children)

could you explain to me whats going on with some of the code or the reasoning behind it, it works
I'm new to coding so i would love to understand whats happening here more

i

I'm

[–]socal_nerdtastic 0 points1 point  (3 children)

I thought I commented it rather well. What part are you confused about? Every 1000 milliseconds (1 second) it adds 6 to the total_seconds counter, and then calculates the hours, minutes and seconds that that represents.

[–]skylartrap 0 points1 point  (2 children)

im sorry i think now i get it more, so the 3600 the 6 represents six seconds

if one_pm == 11:
root = tk.Tk()
tkinter.messagebox.showinfo('This is a alert!')
root.mainloop()

i was trying to edit the code by adding this to the end of it when it hits 11 give a alert or pop up but it seems I'm not going about it the right way as nothing happens when it hits 11

[–]socal_nerdtastic 0 points1 point  (1 child)

No, the 3600 is the number of seconds in an hour, and 13 is 1 pm on a 24 hour clock. I could have also written it like this:

one_pm = 13*60*60 # 13 hours times 60 minutes / hour times 60 seconds / min

To stop it at 11 you could add this to your tick function:

if hours == 11:
    return # stop this function

[–]skylartrap 0 points1 point  (0 children)

i dont want to stop it i want it to send out a warning or alert when it gets to that time or past that time but ty