$\newcommand{\Spec}{\operatorname{Spec}}$I'm working on the following problem from Vakil's notes:
Show that (scheme) morphisms $X\to\Spec A$ are in natural bijection with ring morphisms $A\to\Gamma(X,\mathscr O_X)$.
Of course, any map $X\to\Spec A$ induces a map of global sections $A\to\Gamma(X,\mathscr O_X)$. I am working out the other direction. It is certainly true if $X$ is affine, because affine scheme morphisms $\Spec B\to\Spec A$ are in bijection with ring maps $A\to B$.
In the general case, we cover $X$ with affine open sets $\Spec B_i$. Then for each $i$ we get a map
$$A\to\Gamma(X,\mathcal O_X)\overset{\text{res}}{\to}\Gamma(\Spec B_i,\mathcal O_X)=B_i$$
which in turn gives a map $\pi_i:\Spec B_i\to\Spec A$ (in particular, if we let $\pi_i^{\#}$ be the map $A\to B_i$, then the map is given by $\pi_i(p)=(\pi_i^{\#})^{-1}(p)$).
How can I show that these glue correctly to give a morphism of schemes $\pi:X\to\Spec A$?