Reputation: 841
I need to draw many lines/polygons on a canvas but i want to display the canvas first and then see every object while is drawn.
Here is my code:
root = tk.Tk()
canvas = tk.Canvas(root, height=800, width=800)
canvas.pack()
draw_something(canvas)
root.mainloop()
The problem is that python shows the canvas after drawing everything and this is not what i want.
Upvotes: 1
Views: 1073
Reputation: 36702
In the following example, 10 random lines will be created every second on the canvas.
import tkinter as tk
import random
def make_segment():
return [random.randrange(0, 800) for _ in range(4)]
def draw_random_lines():
canvas.create_line(*make_segment())
root.after(100, draw_random_lines)
root = tk.Tk()
canvas = tk.Canvas(root, height=800, width=800)
canvas.pack()
draw_random_lines()
root.mainloop()
Upvotes: 3