Suppose $u:D\subset \mathbb{R^2}\rightarrow \mathbb{R}$ and $u_x=0$ and $u_y=0$ on $D$. Since $D$ is an open, connected set it is polygonally connected.
Hence if we pick any two points in D, say, $z_0=(a,b)$ and $z_n=(x_n,y_n)$ we then have a sequence of lines i.e $[z_0,z_1]\cup[z_1,z_2]\cup...\cup[z_{n-1},z_n]$. Hence, $z_{0}$ and $z_n $ are connected by a polygonal line.
Consider the line connecting $z_0=(a,b)$ and $z_1=(x_1,x_2)$ i.e $g(t)=(a+t(x_1-a),b+t(x_2-b))=(f(t),g(t))$. Clearly, $g$ is a differentiable vector function since $f(t),g(t)$ are differentiable functions.
We know that $u$ is differentiable on D since $u_x,u_y$ exist in D and are continuous.
Hence, $\frac{du}{dt} =u_x \frac{df}{dt}+u_y \frac{dg}{dt} =0$
Therefore, using mean value theorem, $u(a,b)-u(x_1,x_2) = u(f(0),g(0))-u(f(1),g(1))=u_x(f(t'),g(t'))f'(t')+u_y(f(t'),g(t'))g'(t')=0$
Hence, $u(z_0)=u(z_1)$. Similarly, we can show that $z_0=z_1=...=z_n$. Since $z_n$ is arbitrary, $u$ is constant on D.
I am assuming that more general proofs can be given but is the provided proof sufficient for the given case. (I'm new to multivariable stuff and topology so do let me know if I'm not rigorous enough.)