Proof (locally constant function on connected domain is globally constant)
Take some $x_0\in X$. Define $$ \begin{align*} U ={}& \sb{x\in X}{f(x) = f(x_0)}, \\ V ={}& \sb{x\in X}{f(x) \neq f(x_0)}. \end{align*} $$ Note that both $U$ and $V$ are open: for each $x\in U$ (resp. $V$), there exists an open neighbourhood of $N\subseteq X$ (resp. $V$) of $x$ such that $f(y) = f(x)$ for all $y\in N$ and thus $N\subseteq U$ (resp. $V$). Moreover $U\neq \emptyset$, $X = U\cup V$, and $U$ and $V$ are disjoint. Therefore by connectedness of $X$, we have $V = \emptyset$.