I am making a digital clock python program and don’t know why it says “TypeError: ‘Label’ object is not callable” for line:
JavaScript
x
2
1
digital_clock_lbl(1000, update_clock)
2
I watched a yt video, that’s where I got the code. The guy there didn’t have a problem, but I do. I checked the answer of someone else in stack overflow, they said to not name our variable “Label” because there might be an error, however I haven’t.
JavaScript
1
19
19
1
import tkinter as ui
2
import time
3
4
window = ui.Tk()
5
6
def update_clock():
7
hours = time.strftime("%I")
8
minutes = time.strftime("%M")
9
seconds = time.strftime("%S")
10
am_or_pm = time.strftime("%p")
11
time_text = hours + ":" + minutes + ":" + seconds + " " + am_or_pm
12
digital_clock_lbl.config(text = time_text)
13
digital_clock_lbl(1000, update_clock)
14
15
digital_clock_lbl = ui.Label(window,text="00:00:00",font="Helvetica 72 bold")
16
digital_clock_lbl.pack()
17
update_clock()
18
window.mainLoop()
19
Advertisement
Answer
digital_clock_lbl(1000, update_clock)
doesn’t make sense. I guess you were trying to making a live clock, so I think you need
to use .after
method – window.after(1000,update_clock)
Try this –
JavaScript
1
19
19
1
import tkinter as ui
2
import time
3
4
window = ui.Tk()
5
6
def update_clock():
7
hours = time.strftime("%I")
8
minutes = time.strftime("%M")
9
seconds = time.strftime("%S")
10
am_or_pm = time.strftime("%p")
11
time_text = hours + ":" + minutes + ":" + seconds + " " + am_or_pm
12
digital_clock_lbl.config(text = time_text)
13
window.after(1000,update_clock) # Here is the change
14
15
digital_clock_lbl = ui.Label(window,text="00:00:00",font="Helvetica 72 bold")
16
digital_clock_lbl.pack()
17
update_clock()
18
window.mainloop()
19
Also, you have a typo in last line – window.mainLoop
should be lowercase window.mainloop()