I am developping a little application for plotting a network graph, showing "how fast your ping is". Here is the related code review post.
Basically, I have a thread managing a canvas. This thread targets to the following method (simplified):
def update(self):
# Basically draw a vertical line on the right of the canvas
self.draw_line(tag="spike")
# Move all lines by -1 px and delete the lines outside the canvas
# This can be somewhat long.
lines = list(self.canvas.find_withtag("spike"))
while len(lines) > self.WIDTH:
self.canvas.delete(lines.pop(0))
for l in lines:
x0, y0, x1, y1 = self.canvas.coords(l)
self.canvas.coords(l, x0 - 1, y0, x1 - 1, y1)
# Recall in 10ms
if self.alive:
self.root.after(10, self.update)
So as you might think, this function is a bit slow on large canvas (for example 800x600). Because it uses a recall method after its computation, I have a recall time of computation_time + 10
ms. I would like to have a recall time of exactly 10ms.
As I saw on a SO post about PyGame the method pygame.time.set_timer()
does this kind of thing on PyGame. I would like to know if there is an equivalent for Tkinter
.
Rergards,