I am trying to show that a function that is locally constant on a connected space is, in fact, constant. I have looked at this related question but my approach is a little different than the suggested approach and I'm unsure about the final step and would appreciate a tip. Here is what I have so far:

Let $f$ be a locally constant function on the connected space $U$. Assume that $f$ is not constant. Then, there are distinct points $x$ and $y$ such that $f(x) \neq f(y)$. Now, since $f$ is locally constant there are neighborhoods $V_x$ of $x$ and $V_y$ of $y$ such that

$$
f(V_x) = k_x, \;\; f(V_y) = k_y
$$
for some constants $k_x \neq k_y$ .It follows that $V_x \cap V_y =\emptyset$

Now, let $A = U-V_x \cup V_y$ and $B = V_x \cup V_y$ so that $U = A \cup B$. With this, we have expressed $U$ as a union of disjoint sets. Since $V_x$ and $V_y$ are open $B$ is open. Note that if $A$ is empty we are done because $V_x$ and $V_y$ would comprise a separation of $U$ wich would imply that the assumption about f being not constant was faulty. So, assume $A$ is nonempty.

At this point, I want to show that $A$ itself is open. If I can do this, I believe the proof will be complete. One way I've thought about doing this is to choose a neigborhood of some point $a \in A$ and if it is not already disjoint from $B$, shrink it until it is. This would then demonstrate that $A$ is open. 

Am I on the right track here?

Let $\mathcal{S}$ be the set of open sets in the domain such that $f$ is constant on the open set.

Since $f$ is locally constant, we know that every $x\in \mathrm{dom}\, f$ is a member of some $S\in \mathcal{S}$.

Now, pick $x_0$, and define two sets: $U = \{x: f(x)=f(x_0)\}$ and $V=\{x: f(x)\neq f(x_0)\}$.

We can see that $U$ and $V$ are disjoint, and $U \cup V = \operatorname{dom} f$.

But each of $U$ and $V$ is just a union of open sets, namely sets in $\mathcal{S}$.

So $U$ and $V$ are both open.
