code: def check_if_win(self):
          
          self.flagcount = 0
          win = True
          for x in range(0, len(self.mine_matrix[0])):
              for y in range(0, len(self.mine_matrix)):
                  if self.mine_matrix[y][x].state == 1:
                      self.flagcount += 1
                      if not self.mine_matrix[y][x].has_mine:
                          win = False
                  elif self.mine_matrix[y][x].has_mine:
                      win = False
          self.lblMineCount.set_text("%s" % self.minecount)
          self.lblFlagCount.set_text("%s" % self.flagcount)
          if win:
              self.dialog = gui.GenericDialog(title='You Win!', message='Game done in %s seconds' % self.time_count)
              self.dialog.confirm_dialog.do(self.new_game)
              self.dialog.cancel_dialog.do(self.new_game)
              self.dialog.show(self)
docs: Here are counted the flags. Is checked if the user win.