I just debugged most of my MineSweeper Code in Python, but there is an issue with the game functions that determine a win or loss. If I win, it does not show the desired message box and confirm a win. If I lose, it will show an error message that says messagebox (a tkinter built in function) is undefined.
This is my code for the game:
from tkinter import *
import random
...
def CheckWin(self):
'''Checks if player won'''
doneList = []
for key in self.cells.keys():
if self.cells[key].clicked == True and self.cells[key].value != 9:
doneList.append(self.cells[key])
if len(doneList) == int(height)*int(width)-int(numBombs):
messagebox.showinfo('Minesweeper','Congratulations -- you won!', parent=self)
self.winner = True
def CheckLoss(self):
'''Checks if player lost'''
self.loser = True
self.flagTrack['text'] = '0'
messagebox.showerror('Minesweeper','KABOOM! You lose.', parent=self)
for key in self.cells.keys():
if self.cells[key].value == 9:
self.cells[key].flagged = False
self.cells[key].expose()