How Solar Cells Work
The most common type of solar cell (the cell being the basic building block of the rooftop panel) is made of the common element Silicon. One of the reasons Silicon is used to generate electricity is that in its atomic form, it has a number of electrons that orbit it which are very excitable (in the atomic sense) - but just imagine a room full of small children. When silicon is exposed to light, the photons within the light strike the Silicon electrons and raise them to a very high level of energy until they leave the orbit of the Silicon atom and start bouncing around randomly within the Silicon.
This bouncing around is not, in itself, that useful - now, just imagine a room full of small children who have consumed some quantity of caffeinated soft drink. Eventually, the electrons would just "tire out", give off some heat, and settle back into a comfortable orbit - unless they are given somewhere to go.
If a solar cell were to be cut in half, like a sandwich, it would appear to have two layers - a top layer and a bottom layer. Both layers are made of Silicon, but one has some Phosphorous added and one has some Boron. These additions cause the equivalent of an atomic turnstile or gate at the junction between the two layers that only allows the bouncing electrons to go in one direction.
So, all that's needed is a place to go. That's what wires are for. If a wire is connected to the bottom of the cell, and then looped around to the top, there will be an endless stream of electrons coursing through it as long as the caffeine (Sunlight) is hitting the cell. In very simple terms, this is no different than a flowing river. Now, a motor or light bulb or anything else that runs on direct current electricity can be put in line with this stream of electrons and use the available energy.
Image: US Department of Energy