We can use the same idea if $g:M_n(\mathbb{R})\to\mathbb{R}$. The idea is that if $B$ is a basis of $M_n$, also $g$ and $\text{tr}$ agree on $B$ up to some constant multiple $\alpha$, then $$g(A)=\alpha\cdot \text{tr}(A) $$ for all $A\in M_n$.
Let $E_{i,j}$ be the matrix where all the entries are zero except it is 1 at the position $(i,j)$. Let $T_k=\text{diag}(\underbrace{1,1,\ldots,1}_k,0,\ldots,0)$. Notice that for $i\neq j$ we have $E_{i,j}T_j=E_{i,j}$ while $T_jE_{i,j}=0$. Therefore for all $i\neq j$ we have $g(E_{i,j})=0$.
Now let $J_k$ be a $k\times n$ matrix where all the entries are 1. Define an $n\times n$ matrix $S_k$ as a block matrix $$S_k:=\begin{pmatrix}J_k\\0\end{pmatrix}$$.
Note that since $g(E_{i,j})=0$ for $i\neq j$, we have $g(S_k)=g(T_k)$ for all $k$.
Now
\begin{align*}
S_kS_1&=S_k \\ S_1S_k&=kS_1
\end{align*}
Hence $g(T_k)=g(S_k)=g(kS_1)=kg(S_1)=kg(T_1)$. Notice that the trace map also satisfies $\text{tr}(T_k)=k$. By taking $\alpha=g(T_1)$ then $g$ and $\alpha \cdot \text{tr}$ are two linear maps that agree on $B=\{E_{i,j}\mid i\neq j\}\cup \{T_k\mid k=1,..,n\}$ which is a basis of $M_n$. Hence $g=\alpha\cdot \text{tr}.$