If $f$ is a non-constant analytic function on a compact domain $D$, then $Re(f)$ and $Im(f)$ assume their max and min on the boundary of $D$. This is a homework problem I got, my attempted proof is: 
Since $f$ is non constant and analytic, $f=u(x)+iv(y)$ where neither $u$ nor $v$ is constant(by Cauchy Riemann equations) and $u v$ are both analytic in $D$. 
Therefore $u$ and $v$ both assume their max on the boundary of $D$ (by maximum modulus theorem). 
Also, $u$ and $v$ have no minimums in the interior of $D$ unless they are $0$. I'm stuck here and don't know how to show that $u$ and $v$ are nonzero.

I looked at the answer at the back of the book. They used the Open Mapping Theorem(the image of an open set under a nonconstant analytic mapping is an open set):
According to the Open Mapping Theorem, the image under f of any open set D containing z0 in its interior is an open set containing $f (z_0)$ in its interior. Hence, both Re f and Im f assume larger and smaller values in D than the values $Re f (z_0)$ and $Im f (z_0)$.
I don't understant the proof given by the book, can someone explain a bit? Also, what do you think about my proof?

Here's the book's proof with a tad more detail: Suppose $z_0$ is not on the boundary. We will show neither the real nor the imaginary parts of $f$ are maximized at $z_0$. Since the real and complex parts are continuous, they obtain their maxima and minima somewhere on $D$ because $D$ is compact. Hence they must obtain their minima and maxima on the boundary.
Take a small neighborhood of $z_0$ inside your domain. The image of this open neighborhood is an open neighborhood of $f(z_0)$ by the open mapping theorem. Let $U$ be the neighborhood of $f(z_0)$ just described. For small values of $\varepsilon$, $U$ contains the points $f(z_0)+\varepsilon$ , $f(z_0)-\varepsilon$, $f(z_0)+i\varepsilon$, and $f(z_0)-i\varepsilon$, whose real and imaginary parts are more/less than those of $f(z_0)$.
