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
                try:
                    image = []
                    image.append(PhotoImage(file='1.gif'))
                    image.append(PhotoImage(file='2.gif'))
                    self.square[x][y]['text'] = adjMines
                except (IOError):
                    print 'File missing.'
                else:
                    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:

http://img717.yfrog.com/img717/8660/minegoofup.jpg

(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 6 Years Ago by toll_booth: clarifying what the 'X' is

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

Would be nice to know what self.square is.

Edited 6 Years Ago 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:

self.update()
self.square[x][y].update()

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

self.square.update()

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.