How to pivot a column showing its content as new columns
Found the answer in the next url:
https://vitobotta.com/2015/12/10/mysql-dynamic-column-name/
And I post the example for those who have a similar problem

The final query is:  

DROP TABLE IF EXISTS tmp_proyecto;

CREATE TEMPORARY TABLE tmp_proyecto AS
SELECT DISTINCTROW a.pro_id, a.programa, b.proyecto, CAST(0 AS DECIMAL(8,2)) as total 
FROM programas as a
INNER JOIN presupuesto_aprobado as b ON a.direc = b.direc
WHERE a.direc='31111-0601' AND a.pro_ano=2018
ORDER BY proyecto, pro_id;

SELECT CONCAT('
SELECT pro_id, programa, ',proyectos,'
FROM tmp_proyecto
GROUP BY pro_id
ORDER BY pro_id'
)
INTO @query
FROM
(
SELECT GROUP_CONCAT(CONCAT('IFNULL(MAX(CASE WHEN proyecto=''',proy_actual,''' THEN total END), ''-'') AS "',col_name,'"')) proyectos
FROM (
SELECT proy_actual, CONCAT('P_',proy_actual) AS col_name
FROM (SELECT DISTINCT proyecto AS proy_actual FROM tmp_proyecto) AS unicos
) proy_como_campos
) result;

PREPARE statement FROM @query;
EXECUTE statement;
DEALLOCATE PREPARE statement;


As a result:

pro_id  programa                              P_K0002   P_K0003
191     Empresa Exportadora                   0.00      0.00
192     Apertura de Empresas                  0.00      0.00
223     Promoción y Atracción de Inversiones… 0.00      0.00  


Thanks anyway