I'm trying to code the game of minesweeper. For some reason, the image won't display properly--and it isn't a case of a missing file, b/c I have a try-except code snippet that is set to print out an error message should this occur, and that isn't happening. So either it's misreading the image or just not displaying it properly.

Here is the relevant code (obviously this is a work-in-progress):

if adjMines>0:
                self.square[x][y]['text'] = adjMines
                    image = []
                    self.square[x][y]['text'] = adjMines
                except (IOError):
                    print 'File missing.'
                    if adjMines == 1:
                        self.square[x][y]['text'] = ''
                        self.square[x][y]['image'] = image[0]
                    elif adjMines == 2:
                        self.square[x][y]['text'] = ''
                        self.square[x][y]['image'] = image[1]

BTW, the text thing was what I had going on in the alpha version of the program: It would change the button's text to the appropriate number.

Here is what it looks like:


(And yes, I know the square sizes are goofy. I'm still in the development phase of this program. ETA: On the same token, the 'X' is a mine.)

More importantly, why am I just getting these little gray squares?

Edited by toll_booth: clarifying what the 'X' is

8 Years
Discussion Span
Last Post by toll_booth

You might need to use self.update() or self.square.update()

Would be nice to know what self.square is.

Edited by vegaseat: n/a


You might need to use self.update() or self.square.update()

Would be nice to know what self.square is.

"square" is a two-dimensional list of buttons.

I inserted the following two lines:


at the end of the above section. No change. But strangely, when I insert this line:


I get an error, which is to be expected since square is a list. But I can see a squashed image in the little gray square! And when another 1- or 2-space is selected, the image moves to that square.

Is it simply a matter of the size of the contained image square?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.