我正在尝试轮询 Gtk 应用程序中的函数。代码是...
from gi.repository import Gtk
import sys,threading
def destroy(k):
print "destroyed"
sys.exit()
def poll():
print "called it "
t=threading.Timer(1,poll)
t.start()
build=Gtk.Builder()
build.add_from_file('test.glade') # it just creates a top level window
window=build.get_object("boxy")
build.connect_signals({"destroyit":destroy})
window.show_all()
t=threading.Timer(1,poll)
t.start()
Gtk.main()
轮询函数没有执行..但是如果我删除 Gtk.main() ,它工作正常......那么发生了什么......为什么它在没有 main 而不是 main 的情况下工作......以及如何执行这个中的轮询函数..除了threading.timer还有其他选择吗?
编辑:我通过使用 GObject.timeout_add(5000,poll) 找到了解决方法,但我仍然想知道,为什么 threading.Timer 函数不执行......