list of Canvases contais only Nones

Laura Creighton lac at strakt.com
Mon Jan 27 16:26:04 EST 2003


> > hello,
> > 
> > i am creating a frame with a lot of small canvases on it ant want to
> > store the references in a list, but i get a list of nones instead.
> > the frame gets created and shows all the canvases! so they are 
> > definitely somewhere.
> > 
> > whats wrong with my code?
> > 
> > #my try:
> > 
> > canv_list = []
> > root = Tkinter.Tk()
> > for j in range(0,y_nr):
> >      for i in range(0,x_nr):
> >          canv_list.append(Tkinter.Canvas(root,
> >                                          width = x_size,
> >                                          height = y_size,
> >                                          background = 'white',
> >                                          border = 0
> >                                          ).grid(row=j,column=i)
> >                           )
> > print canv_list
> > 
> > # the output of this code:
> > 
> > [None, None, None, None, None, None]
> > 
> > Thanks for help, Meinrad Recheis
> > 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> <anything>.grid, and <anything>.pack return None.  You need to make a
> list of widget, row, col triplets, and then grid them all in a later
> step.
> 
> Laura Creighton

Following up my own post, bleah ...

This is assuming that you want to keep those rows and columns
someplace so you could, for intance, store them again.  If all
you need to do is make a list of of your widgets, then you just
say widget = Tkinter.Canvas(whatever)
    canv_list.append(widget)
    widget.grid(row=j,column=i)

Laura







More information about the Python-list mailing list