Let $\psi:A \rightarrow B$ be a ring map. Consider the induced map on affine scheme: $f: Y = \operatorname{Spec}B \rightarrow X = \operatorname{Spec}A$. Why is it true that $f^{-1}D(g) = D(\psi(g))$, where $g \in A$?
We know that the pullback of a prime ideal is prime. Thus it is clear that $f^{-1}D(g) \subset D(\psi(g))$. But I cannot see why the other direction holds.
Note that: $f(P)=\psi^{-1}(P)$ for $P\in Spec(B)$. Actually, $f^{-1}(D(g)) = D(\psi(g))$ for every $g\in A$, since $P\in f^{-1}(D(g))$ if and only if $f(P) \in D(g)$ if and only if $\psi^{-1}(P) \in D(g)$ if and only if $g\not\in \psi^{-1}(P)$ if and only if $\psi(g)\not\in P$ if and only if $P\in D(\psi(g))$.