So basically, I'm trying to make a digital clock in python, to show up on a little window when I run the program. I had two ideas on how to make these, but the code below is the same. My problem is: if I use the time.sleep
command, when I run the program, the window doesn't even pop up, but if I use root.after(1000, clock(root, w)
, the window appears but it creates 1000 of the labels, giving the "recursion depth exceeded" error. Any help?
import time as t
import tkinter as tk
from datetime import datetime
def main():
root = tk.Tk()
root.title("Digital Clock")
w = tk.Label(font = (100))
w.pack()
clock(root, w)
root.mainloop()
def clock(root, w):
t.sleep(1)
timelabeled = " "
now = datetime.now()
timelabeled = ("%s/%s/%s %s:%s:%s" % (now.day, now.month, now.year, now.hour, now.minute, now.second))
w.config(text = timelabeled, )
root.after(clock(root, w))
if __name__ == "__main__":
main()
My result is supposed to be a little window with a label representing the time, which gets updated every second, but that's not what I'm getting. Either I get nothing, or 1000 labels that don't update.