Q:

Tkinter after that survives clock rewinding

I noticed that in my version of Tkinter, the after() call does not survive system clock rewinding.
If the after(x, func) was called, and the system clock was rewinded, func will be called only after the clock returned to its time before the rewind + x milliseconds.
I assume this is because Tkinter uses the system-clock instead of the "time.clock" (the amount of time that the program is running).
I tested it only on windows, and maybe its because I have an old version of Tkinter.
I want my App to work on computers that synchronize their clock from the network...
Does anyone have a simple solution?

A:

Unfortunately, neither Tkinter nor Tcl interpreter have an straightforward solution to your problem. The after(ms, func) method is based on the Tcl command of the same name, which creates an internal timer based on the current system time plus the amount of milliseconds passed as parameter.
In case you are curious, you can check it out directly from the Tcl/Tk source code:
Tcl_GetTime(&wakeup);
wakeup.sec += (long)(ms / 1000);
wakeup.usec += ((long)(ms % 1000)) * 1000;
if (wakeup.usec > 1000000) {
    wakeup.sec++;
    wakeup.usec -= 1000000;
}
afterPtr->token = TclCreateAbsoluteTimerHandler(&wakeup,
    AfterProc, afterPtr);

Given this limitation, I would go for a pure Python approach, like using a Timer:
import time
import threading
import tkinter as tk

root = tk.Tk()

def say_hi():
    print(time.perf_counter(), "-", "Hi after 30sec!")
    root.destroy()

print(time.perf_counter(), "-", "Waiting 30sec")
threading.Timer(30, say_hi).start()
root.mainloop()

It also has the advantage that runs on a separate thread, preventing not only blocking the GUI during the timer interval but also while executing the callback function.

