[Tutor] MineSweeper

Adam Cripps kabads at gmail.com
Sat Jun 25 19:24:20 CEST 2005

On 6/25/05, Alberto Troiano <albertito_g at hotmail.com> wrote:
> Hey Tutors
> I have a question
> I want to make a minesweeper (just for practice) but I don't what can I use
> to make the GUI
> I was thinking about buttons (click event you know) and change the
> background image on change
> Maybe there's another widget to use
> My doubt is that I want to be able to allow the user to put how many bombs
> they want and how any spaces (how big is the board) so I will have to create
> buttons dinamically, but in doing this the reference to the buttons will be
> lost
> How do I know which button did I click when all buttons have the same name?
> Does this make sense?
> I recall in VB.6.0 the control matrix but I never knew how to use it
> Any help?
> Thanks in advanced
> Alberto

I have written some similar code to this - you give each button a
different name through an interator.

You can see my code at:

http://www.sf.net/projects/jiletters and follow the links to the CVS
code repository.

For that, I used wxPython, but it's up to you what you go for. 

The main part that may be useful to you is:

        for i in noduplicatesalphabet:
            identity = int(D[i]) + 29 # It's quicker to add 29 than go
through and edit the dictionary by hand
            bmp = wxBitmap('alphabet_graphics/' + i + '.bmp', wxBITMAP_TYPE_BMP)
            self.grafic =wxBitmapButton(self,
            EVT_BUTTON(self, identity, self.ButtonPushed)

The noduplicates is a list that I generated by hand, but you could do
this in a range(a,b) way if it's not attached to any particular data
or meaning.

The EVT_BUTTON passes the id to the function self.ButtonPushed, which
then can tell which button was pushed.


PGP key: 0x7111B833

More information about the Tutor mailing list