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?

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

Would be nice to know what self.square is.

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?

Someone please help me. I need this taken care of ASAP.

I'm gonna try out PIL.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.