I'm making a little program with tkinter and trying to get this timer to work. I'm getting a "'float' is not callable" error. Does anyone know what I'm doing wrong?

The error happens when it tries to call 'self.clock_start()'

    def create_widgets(self):
        #create the main frame
        self.root = Tk()
        self.root.title("Learning Timer")
        self.clock_start = time.clock()

        #create the frame we're building on
        self.frame = ttk.Frame(self.root, padding="5 5 15 15")
        self.frame.grid(column=0, row=0, sticky=(N,S,W,E))

        #create the main program image
        self.main_image = PhotoImage(file="mainimage.gif")
        self.dislay_main_image = ttk.Label(self.frame, image=self.main_image)
        self.dislay_main_image.grid(row=0, column=0, sticky=N)

        #create the listbox
        self.what = StringVar()
        self.list = Listbox(self.frame, width=41, height=5)
        self.list.insert(1, "Programming")
        self.list.insert(2, "Mathematics")
        self.list.grid(row=1, column=0, sticky=N)

        self.button = ttk.Button(self.frame, text="CLICK ME", command=self.update)
        self.button.grid(row=2, column=0)

        self.label = ttk.Label(self.frame, text="")
        self.label.grid(row=3, column=0, sticky=N)

        self.time_label = ttk.Label(self.frame, text="")
        self.time_label.grid(row=4, column=0, sticky=N)

        self.clock_start()
        self.frame.mainloop()
        self.root.mainloop()

    def clock_start(self):
        self.time_elapsed = time.clock() - self.clock_start
        self.time_label["text"] = str(self.time_elapsed)
        self.frame.after(1000, self.clock_start)

Recommended Answers

All 2 Replies

() implies a function call

You are using
self.clock_start = time.clock()
and
def clock_start(self):

This method would be called with self.clock_start(), but the name is used by a variable of the same name containing a float value. Simply rename one of them.

It does not make sense to substract function from value (in __init__ actually you are overwriting this function with current time, so you can not call it anyway):

self.time_elapsed = time.clock() - self.clock_start
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.