[英]python GTK 3 Glade 3 Timer
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.
每当我执行代码时,它都会显示开始倒计时的时间值,然后倒计时 1 秒。 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:我之前没有真正使用过 PyGTK,但从我看来,问题很可能出在
startcycletimer
方法中:
It should rather be GObject.timeout_add_seconds(1, self.displaytimer)
instead of GObject.timeout_add_seconds(1, self.displaytimer(counter))
.它应该是
GObject.timeout_add_seconds(1, self.displaytimer)
而不是GObject.timeout_add_seconds(1, self.displaytimer(counter))
。
You need to pass the caller to the function and not the output.您需要将调用者传递给函数而不是输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.