The principle of an electroscope is based on the atomic structure of elements, the internal structure of metal elements, charge induction, and the idea that like charges repel and opposite charges attract.
All elements are composed of electrons, protons, and neutrons - with the electrons surrounding the nucleus. In metals these outer electrons are loosely held by the nuclei and are relatively free to move within the material.
An electroscope has a metal detector knob on top which is connected to a pair of metal leaves hanging from the bottom of the connecting rod.
When no charge is present the metal leaves hang loosely downward.
However, if an object with a charge is brought near the electroscope, one of two things can happen.
If the charge is positive, electrons in the metal of the electroscope are attracted to the charge and move upward out of the leaves. This causes the leaves to have a temporary positive charge and because like charges repel, the leaves separate. When the charge is removed, the electrons return to their original positions and the leaves relax.
Likewise, if the charge is negative, the electrons in the metal of the electroscope are repelled and move toward the leaves on the bottom. This causes the leaves to have a temporary negative charge and because like charges repel, the leaves again separate. Then when the charge is removed, the electrons return to their original position and the leaves relax.
So an electroscope reacts to the presence of a charge through the movement of electrons either into, or away from, the leaves. In either case the leaves separate. But the electroscope cannot tell if the charged object has a positive charge or a negative charge - it is only responding to the presence of an electrical charge.