Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'below)': 0.07; 'column': 0.07; 'mouse': 0.07; 'responding': 0.07; 'subject:Question': 0.07; 'python': 0.09; 'buttons': 0.09; 'grid': 0.09; 'bind': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'perhaps:': 0.16; 'row': 0.16; 'subject:Programming': 0.16; 'wrote:': 0.17; 'fairly': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'efficiently': 0.29; 'received:192.168.1.3': 0.29; 'code': 0.31; 'to:addr:python- list': 0.33; 'skip:b 20': 0.34; 'text': 0.34; 'something': 0.35; 'there': 0.35; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:...': 0.63; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'click': 0.76; 'subject::': 0.83; '(ie': 0.84; 'reply- to:addr:python.org': 0.84; 'subject: ...': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=KqrPKBqN c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=YsUzL_8ObRgA:10 a=37iT0KVkS4oA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=706QETRFC8cu2VsGxGEA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Thu, 28 Jun 2012 00:43:14 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Question:Programming a game grid ... References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1340840605 news.xs4all.nl 6927 [2001:888:2000:d::a6]:32820 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24564 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('', leftclick) # bind left mouse click b.bind('', rightclick) # bind left mouse click buttons['{0}{1}'.format(row, column)] = b