Skip to content
Advertisement

Why does it say “TypeError: ‘Label’ object is not callable”?

I am making a digital clock python program and don’t know why it says “TypeError: ‘Label’ object is not callable” for line:

    digital_clock_lbl(1000, update_clock)

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.

import tkinter as ui
import time

window = ui.Tk()

def update_clock():
    hours =  time.strftime("%I")
    minutes = time.strftime("%M")
    seconds = time.strftime("%S")
    am_or_pm = time.strftime("%p")
    time_text = hours + ":" + minutes + ":" + seconds + " " + am_or_pm
    digital_clock_lbl.config(text = time_text)
    digital_clock_lbl(1000, update_clock)

digital_clock_lbl = ui.Label(window,text="00:00:00",font="Helvetica 72 bold")
digital_clock_lbl.pack()
update_clock()
window.mainLoop()

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 –

import tkinter as ui
import time

window = ui.Tk()

def update_clock():
    hours =  time.strftime("%I")
    minutes = time.strftime("%M")
    seconds = time.strftime("%S")
    am_or_pm = time.strftime("%p")
    time_text = hours + ":" + minutes + ":" + seconds + " " + am_or_pm
    digital_clock_lbl.config(text = time_text)
    window.after(1000,update_clock) # Here is the change

digital_clock_lbl = ui.Label(window,text="00:00:00",font="Helvetica 72 bold")
digital_clock_lbl.pack()
update_clock()
window.mainloop()

Also, you have a typo in last line – window.mainLoop should be lowercase window.mainloop()

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement