[Tkinter-discuss] How to Reference many Canvas Ovals

Pavel Kosina geon at post.cz
Thu May 4 17:40:48 CEST 2006


electron at borgmeyer.com napsal(a):
> EHLO! Anyone have code showing how to reference many individual Canvas 
> objects? 
put them into list
> for i in range(1,number+1)
> n[i] = canvas.create_oval()
instead of this, there should be something like

for i in range(1000):
    x,y=random.randint(0,X), random.randint(0,Y)
    o=canvas.create_oval((x,y,x+10,y+10), fill='red')
> and
> if variable[i] == "blue" then canvas.n[i].config(fill='blue') 
no, again, if you want to change color of 578th :-) oval, do it this way:
canvas.itemconfig(all[578-1], fill='pink')

Pavel Kosina

More information about the Tkinter-discuss mailing list