Question:Programming a game grid ...
MRAB
python at mrabarnett.plus.com
Wed Jun 27 19:43:14 EDT 2012
On 27/06/2012 23:21, iconoclast011 wrote:
> Fairly new to Python ... Is there a way to efficiently (different from my brute
> force code shown below) to set up a game grid of buttons (ie with pygame)
> responding to mouse clicks ? I would want to vary the size of the grid ...
>
[code snipped]
Something based around this, perhaps:
buttons = {}
for row in range(10):
for column in range(9):
b = Button(f3, text = "{0}{1}".format(row, column), bg = "white")
b.grid(row=0, column=0)
b.bind('<Button-1>', leftclick) # bind left mouse click
b.bind('<Button-3>', rightclick) # bind left mouse click
buttons['{0}{1}'.format(row, column)] = b
More information about the Python-list
mailing list