我是 Tkinter 的新手,所以如果这很容易,我深表歉意,但我已经搜索了几个小时并且无法弄清楚。我想做的是在主循环空闲后,我总是想调用函数checkForGroupUpdates()。当我运行下面的代码时,它只运行一次。我无法弄清楚每次主循环空闲时都让它运行。我很感激帮助。
from Tkinter import *
import random
class Network(Frame):
""" Implements a stop watch frame widget. """
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
self.makeWidgets()
def makeWidgets(self):
""" Make the time label. """
self._canvas = Canvas(self, width=600, height=400)
self._canvas.pack()
def checkForGroupUpdates(self):
print "checking"
h=0
this=10
while this>.0001:
this=random.random()
print h
h=h+1
print "checked"
def main():
root = Tk()
nw = Network(root)
nw.pack(side=TOP)
root.after_idle(nw.checkForGroupUpdates)
root.mainloop()
if __name__ == '__main__':
main()