Solving partial differential equation in 2d with 3 boundary conditions
The periodic boundary condition tells you that the solution is $\pi$-periodic in $x$-direction, or at least can be interpreted as such if suitably extended outside the rectangle. This means that in that direction you get a Fourier series expansion $$ u(x,y)=\frac{a_0(y)}2+\sum a_k(y)\cos(2kx)+b_k(y)\sin(2kx). $$ This gives the same result as the separation approach, but starting from a different direction.
Comparing the conditions on the upper and lower boundaries gives $b_1(0)=b_1(4)=\frac12$, $a_0(4)=8$, all other coefficients are zero at $y=0$ and $y=4$. Further, $$ -Δu(x,y)=-\frac{a_0''(y)}2+\sum_k[4k^2a_k(y)-a_k''(y)]\cos(2kx)+[4k^2b_k(y)-b_k''(y)]\sin(2kx). $$ Now comparing coefficients and solving the simple DE gives $$ a_0(y)=2y,\\ b_1(y)=\frac{\cosh(2(y-2))}{2\cosh(4)}, $$ all other coefficient functions being zero.