I have a problem with getting a simple timer to work. Whenever I execute the code, it will display the starting time value to countdown from and then count down 1 second. After that, I receive the following error:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\gi\overrides\GLib.py", line 633, in <lambda>
return (lambda data: callback(*data), user_data)
TypeError: 'bool' object is not callable
Below is my code:
from gi.repository import Gtk, GObject
class Main:
def __init__(self):
# create an instance of the builder
self.builder = Gtk.Builder()
self.builder.add_from_file('Main_ver_c.glade')
self.builder.connect_signals(self)
# Setup the main window
self.window = self.builder.get_object("program_main")
self.window.set_title("Automated Benchtop Medical Device Cleaner")
self.window.show_all()
# Setup Timer
self.labelcycle = self.builder.get_object('stage_time')
# Closes program on 'X' press
def on_DeleteWindow(self, object, data=None):
print ("quit with cancel")
Gtk.main_quit()
# Displays Timer
def displaytimer(self,time):
state = True
self.labelcycle.set_text(str(time))
print(time)
time -= 1
print(time)
if time < 0:
state = False
print("timer stop")
return True
# Initialize Timer
def startcycletimer(self, counter):
GObject.timeout_add_seconds(1, self.displaytimer(counter))
if __name__ == '__main__':
main = Main()
main.startcycletimer(5)
Gtk.main()
I haven't really used PyGTK before, but from what I see the issue is most probably in the startcycletimer
method:
It should rather be GObject.timeout_add_seconds(1, self.displaytimer)
instead of GObject.timeout_add_seconds(1, self.displaytimer(counter))
.
You need to pass the caller to the function and not the output.