开发者

Python Tkinker events [duplicate]

This question already has answers here: How can I schedule updates (f/e, to update a clock) in tkinter? (8 answers) Closed 9 years ago.

I would want to use time to enable event's callback function in Tkinter.

How do I do something like this using Tkinter

ftime  = time()
while 1:
    if ftime - time开发者_运维技巧() > 2000:
        dosomething
        ftime = time()

Note that all I wanted is being able to use time passed to call callback function

Janus


You can use the Tkinter method after to schedule a command to run after a given number of milliseconds. That's considerably better than implementing a tight loop. Remember: the event loop is already an infinite loop, nesting a long running loop inside it causes performance problems.

If you want something to be called more than once after a given period of time you can have a job call itself at regular intervals. There is an example in this answer to the question How to create a timer using tkinter?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜