The following question is already answered here but I want to know how far away my attempt is from being correct. Let $P, A \in M_n(\mathbb{R})$ where $P^2=P$ and $AP=PA.$ Show that $A$ must be a scalar matrix.
My attempt: Since $P^2=P,$ if $\text{rank} P= n-k,$ we know that $P$ must be diagonalisable with eigenvalues $0$ and $1$ with multiplicities $k$ and $n-k$ respectively. Further, $P^2=P$ implies $\text{ker P} \cap \text{range} P=\{0\}$ and $\text{range} P = \text{ker}(P-I)$ so if $V$ is a real vector space of dimension $n$ then $V= \text{ker}P \bigoplus \text{range}P= \text{ker}(P-I) \bigoplus \text{ker}(P-I).$ Also, since $AP=PA, $ both $\text{ker}(P-I) $ and $\text{ker}P$ are invariant under $A$ so if $B=\{v_i\}_{i=1}^n$ is a basis of $V$ consisting of eigenvectors of $P,$ then the matrix of $A$ with respect to $B$ must be block diagonal. It remains to show that each of these blocks must be scalar matrices, with the same scalar. In short, I have gotten as far as this answer has but have been unable to make further headway. Any hints on finishing along this line of argument? Thanks, in advance.