newbie, re: tkinter canvas

Steven Taschuk staschuk at telusplanet.net
Sat Mar 8 00:15:52 EST 2003


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

-- 
Steven Taschuk                                7\ 7'Z {&~         .
staschuk at telusplanet.net                        Y r          --/hG-
                                            (__/ )_             1^1`





More information about the Python-list mailing list