When I draw a rectangle at global scope:
c = Canvas(width=IMAGE_WIDTH, height=IMAGE_HEIGHT, bg='black')
c.create_rectangle([100, 100, 110, 110], fill='white')
c.pack()
root = Tk()
and follow this by drawing multiple rectangles in a loop
class gDrawer :
def __init__(self) :
self.rect_array = []
self.x = 0
self.y = 0
def incr_counter(self,c,event=None):
one_pixel_loc = [self.x, self.y, self.x+5, self.y+5]
self.rect_array.append(c.create_rectangle(one_pixel_loc, fill='white'))
self.x += 1
gd = gDrawer()
for xx in range(100) :
print xx
gd.incr_counter(c)
root.mainloop()
The single drawn rectangle stays on the canvas while the loop drawn rectangle moves rather than creating a trail of rectangles. I’d like to draw a trail of rectangles and not a moving one, so what is going on here?
The default color for the outline of a
rectangleisblack. This makes it seem like the other rectangles aren’t being drawn when their outline is just overlapping.Try changing:
to this:
Not sure if this is exactly what you’re looking for, hope it helps.