Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Question:Programming a game grid ...

Thread Tools

Re: Question:Programming a game grid ...

Posts: n/a
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
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Game programming for kids: looking for open source 2D game developmentkit Max Kubierschky Python 10 03-31-2007 07:18 PM
I need help with card game game of war in GUI enviroment judith Java 0 11-01-2006 06:11 AM
Java Game- Game can't find it's graphics jar file BlackHawke Java 12 01-26-2004 06:14 AM