0

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

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
user618677
  • 4,909
  • 6
  • 23
  • 24

1 Answers1

0

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?

Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685