Tkinter only calls after_idle once

后端 未结 2 540
离开以前
离开以前 2020-12-18 03:01

I am new to Tkinter, so I apologize if this is easy, but I have search for a couple of hours and can\'t figure it out. What I want to do is after the mainloop is idle, I al

2条回答
  •  清歌不尽
    2020-12-18 03:39

    Instead of calling the function all the time when the app is idle, you should just call it once every fraction of a second. For example, if you want to check 10 times every second you would do something like this:

    def checkForGroupUpdates(self):
        
        self.after(100, self.checkForGroupUpdates)
    

    Once you call that function once, it will arrange for itself to be called again in 100ms. This will continue until the program exits. If the program goes "non-idle" (ie: while responding to a button click), this function will pause since tkinter is single-threaded. Once the program goes idle again, the check will continue.

提交回复
热议问题