Tkinter: Analog Clock Refreshing - How Does "after" Function Work?
Solution 1:
The problem is that in the principle function, HORLOGE1()
calls itself immediately while trying to arrange for it to be called again after the specified 1 second delay. This occurs in the last line:
fen1.after(1000, HORLOGE1(250, 250, 200))
A simple way prevent this, would be to use something like this instead:
fen1.after(1000, lambda: HORLOGE1(250, 250, 200))
What this does is create an anonymous function using a lambda
expression . The function created accepts/requires no arguments, and all it does is call HORLOGE1(250, 250, 200)
when it's called. That function is what is then passed to fen1.after()
as the second argument.
The notable thing is that doing this does not actually call HORLOGE1()
in the process. The second argument to .after()
should almost always be a callable — such as a function or a bound method — rather than the results of calling one, as you are doing.
After making the change, you should see something like this with moving clock hands on it:
Post a Comment for "Tkinter: Analog Clock Refreshing - How Does "after" Function Work?"