newbie, re: tkinter canvas
Locash
built4living at excite.com
Sat Mar 8 22:42:31 EST 2003
Steven,
Thanks for all your comments.
I now understand why "self.world.img = imgL" works in createWidgets,
but not createLife.
As far as this latest comment is concerned, I guess I was just
thinking too hard.
Thanks again.
locash
Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1047096673.2829.python-list at python.org>...
> One more thing...
>
> Quoth Locash:
> [...]
> > def createLife(self, event):
> >
> > imgL = PhotoImage(file='life.gif')
> >
> > x = int(((event.x + 5)/10))*10
> > y = int(((event.y + 5)/10))*10
> >
> > for i in range (0, len(self.currentGen)):
> > for j in range (0, len(self.currentGen[i])):
> > if x == (i*10) and y == (j*10):
> > self.world.create_image(x, y, image=imgL)
> > self.currentGen[i][j] = imgL
> > else: pass
> > self.world.img = imgL
>
> I find this loop puzzling. Why not just do this?
>
> x = int(((event.x + 5)/10))*10
> y = int(((event.y + 5)/10))*10
> try:
> self.currentGen[x/10][y/10] = imgL
> self.world.create_image(x, y, image=imgL)
> except IndexError:
> # x,y outside of generation
> pass
More information about the Python-list
mailing list